Changeset 1149


Ignore:
Timestamp:
Jul 3, 2011, 7:44:01 PM (6 years ago)
Author:
joerg
Message:

created object for the rows of a document for more fine grained syncs

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/JLatexEditorJFrame.java

    r1139 r1149  
    289289    settingsMenu.add(createMenuItem("Font", "font", 'F'));
    290290    JMenu forwardSearch = new JMenu("Forward Search") {{
    291       add(createMenuItem("Skim", "forward search: /Applications/Skim.app/Contents/SharedSupport/displayline %line \"%file.pdf\" \"%texfile\"", null));
    292       add(createMenuItem("xdvi", "forward search: xdvi -sourceposition \"%line %file.dvi\" -nofork", null));
    293       add(createMenuItem("kdvi", "forward search: kdvi --unique \"file:%file.dvi#src:%line %texfile\"", null));
    294       add(createMenuItem("okular", "forward search: okular --unique \"file:%file.pdf#src:%line %texfile\"", null));
     291      for(Wizard.ProgramWithParameters program : Wizard.VIEWERS) {
     292        add(createMenuItem(program.getName(), "forward search: " + program.getExecutable() + " " + program.getParameters(), null));
     293      }
    295294    }};
    296295    settingsMenu.add(forwardSearch);
  • trunk/src/jlatexeditor/errorhighlighting/LatexCompiler.java

    r1110 r1149  
    282282
    283283    try {
     284      String bibExecutable = GProperties.getString("compiler.bibtex.executable");
     285      String dvipsExecutable = GProperties.getString("compiler.dvips.executable");
     286      String ps2pdfExecutable = GProperties.getString("compiler.ps2pdf.executable");
     287
    284288      errorView.compileStarted("bibtex");
    285       String exe = GProperties.getString("compiler.bibtex.executable");
    286       bibtex = ProcessUtil.exec(new String[]{exe, baseName}, file.getParentFile());
     289      bibtex = ProcessUtil.exec(new String[]{bibExecutable, baseName}, file.getParentFile());
    287290      bibtex.waitFor();
    288291
    289292      if (type == Type.dvi_ps || type == Type.dvi_ps_pdf) {
    290         Process dvips = ProcessUtil.exec(new String[]{"dvips", baseName + ".dvi"}, file.getParentFile());
     293        Process dvips = ProcessUtil.exec(new String[]{dvipsExecutable, baseName + ".dvi"}, file.getParentFile());
    291294        dvips.waitFor();
    292295      }
    293296      if (type == Type.dvi_ps_pdf) {
    294         Process ps2pdf = ProcessUtil.exec(new String[]{"ps2pdf", baseName + ".ps"}, file.getParentFile());
     297        Process ps2pdf = ProcessUtil.exec(new String[]{ps2pdfExecutable, baseName + ".ps"}, file.getParentFile());
    295298        ps2pdf.waitFor();
    296299      }
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1133 r1149  
    211211    properties.addEntry(new Def("compiler.latex.executable", STRING, "latex"));
    212212    properties.addEntry(new Def("compiler.latex.parameters", STRING, "--src-specials"));
     213    properties.addEntry(new Def("compiler.dvips.executable", STRING, "dvips"));
     214    properties.addEntry(new Def("compiler.ps2pdf.executable", STRING, "ps2pdf"));
    213215    properties.addEntry(new Comment(" bibtex"));
    214216    properties.addEntry(new Def("compiler.bibtex.executable", STRING, "bibtex"));
  • trunk/src/jlatexeditor/gui/Wizard.java

    r1126 r1149  
    22
    33import de.endrullis.utils.BetterProperties2;
    4 import jlatexeditor.SCEManager;
    54import jlatexeditor.gproperties.GProperties;
    6 import util.ProcessUtil;
    75import util.StreamUtils;
    86
     
    108import javax.swing.border.EtchedBorder;
    119import javax.swing.border.TitledBorder;
    12 import javax.swing.event.DocumentEvent;
    13 import javax.swing.event.DocumentListener;
    1410import java.awt.*;
    15 import java.awt.event.WindowEvent;
    16 import java.awt.event.WindowListener;
     11import java.awt.event.*;
    1712import java.io.*;
    18 import java.sql.Array;
    1913import java.util.ArrayList;
    2014import java.util.HashMap;
    2115
    2216public class Wizard extends JDialog implements WindowListener {
     17  private static final int OS_LINUX = 0;
     18  private static final int OS_MAC = 1;
     19  private static final int OS_WINDOWS = 2;
     20
     21  public static final ProgramWithParameters[] VIEWERS = new ProgramWithParameters[] {
     22          new ProgramWithParameters("kdvi", "kdvi", "--unique \"file:%file.dvi#src:%line %texfile\""),
     23          new ProgramWithParameters("okular", "okular", "--unique \"file:%file.pdf#src:%line %texfile\""),
     24          new ProgramWithParameters("Skim", "/Applications/Skim.app/Contents/SharedSupport/displayline", "%line \"%file.pdf\" \"%texfile\""),
     25          new ProgramWithParameters("xdvi", "xdvi", "-sourceposition \"%line %file.dvi\" -nofork"),
     26          new ProgramWithParameters("SumatraPDF", "SumatraPDF.exe", "TODO"),
     27  };
     28
     29  private static int OS = OS_LINUX;
     30  static {
     31    String osName= System.getProperty("os.name");
     32    if(osName != null && osName.toLowerCase().indexOf("mac") >= 0) {
     33      OS = OS_MAC;
     34    }
     35    if(osName != null && osName.toLowerCase().indexOf("windows") >= 0) {
     36      OS = OS_WINDOWS;
     37    }
     38  }
     39
    2340  private String message =
    2441          "<font size=+2><bf>Welcome to JLatexEditor!</bf></font><br><br> " +
     
    3148    toolLocations.put("pdflatex" , new ArrayList<File>());
    3249    toolLocations.put("latex" , new ArrayList<File>());
     50    toolLocations.put("dvips" , new ArrayList<File>());
     51    toolLocations.put("ps2pdf" , new ArrayList<File>());
    3352    toolLocations.put("bibtex" , new ArrayList<File>());
     53
     54    if(OS == OS_LINUX) {
     55      toolLocations.put("xdvi" , new ArrayList<File>());
     56      toolLocations.put("kdvi" , new ArrayList<File>());
     57      toolLocations.put("okular" , new ArrayList<File>());
     58    } else
     59    if(OS == OS_MAC) {
     60      toolLocations.put("Skim.app/Contents/SharedSupport/displayline" , new ArrayList<File>());
     61    } else
     62    if(OS == OS_WINDOWS) {
     63      toolLocations.put("SumatraPDF" , new ArrayList<File>());
     64    }
    3465  }}
    3566
    36   private JTextField aspell = new JTextField();
    37   private JTextField pdfLatex = new JTextField();
    38   private JTextField latex = new JTextField();
    39   private JTextField bibtex = new JTextField();
     67  private JComboBox aspell = new JComboBox();
     68  private JComboBox pdfLatex = new JComboBox();
     69  private JComboBox latex = new JComboBox();
     70  private JComboBox dvips = new JComboBox();
     71  private JComboBox ps2pdf = new JComboBox();
     72  private JComboBox bibtex = new JComboBox();
     73  private JComboBox viewer = new JComboBox();
     74  private JTextField viewerParameters = new JTextField();
    4075
    4176  private String[][] importantKeyStrokes = new String[][] {
     
    6297    super(owner, "Quick Setup Wizard");
    6398
    64     Container cp = getContentPane();
     99    JPanel main = new JPanel();
     100    JScrollPane scrollPane = new JScrollPane(main);
     101
     102    getContentPane().setLayout(new BorderLayout());
     103
     104    JLabel welcome = new JLabel("<html>" + message + "</html>");
     105    welcome.setBorder(BorderFactory.createEmptyBorder(0,5,15,5));
     106    welcome.setOpaque(false);
     107    getContentPane().add(welcome, BorderLayout.NORTH);
     108    getContentPane().add(scrollPane, BorderLayout.CENTER);
     109
    65110    GridBagLayout layout = new GridBagLayout();
    66111    GridBagConstraints gbc = new GridBagConstraints();
    67     cp.setLayout(layout);
     112    main.setLayout(layout);
    68113
    69114    gbc.fill = GridBagConstraints.BOTH;
     
    72117
    73118    gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1;
    74     gbc.weightx = .2; gbc.weighty = 1;
    75     JLabel welcome = new JLabel("<html>" + message + "</html>");
    76     welcome.setOpaque(false);
    77     cp.add(welcome, gbc);
    78 
    79119    gbc.weightx = 1; gbc.weighty = .2;
    80120
    81121    JPanel keystrokesPanel = new JPanel(new BorderLayout());
    82     keystrokesPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
    83             "Select KeyStroke Settings"));
     122    TitledBorder border = new TitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "KeyStroke Settings");
     123    border.setTitleFont(border.getTitleFont().deriveFont(Font.BOLD));
     124    keystrokesPanel.setBorder(border);
    84125
    85126    if(GProperties.hasChanges()) {
     
    112153    keystrokesPanel.add(keyStrokesList, BorderLayout.CENTER);
    113154
    114     gbc.gridy++;
    115     cp.add(keystrokesPanel, gbc);
    116 
    117     gbc.gridy++;
    118     cp.add(createProgramPanel("Aspell", "aspell.executable", aspell,
     155    main.add(keystrokesPanel, gbc);
     156
     157    gbc.gridy++;
     158    main.add(new ProgramPanel("Aspell", "aspell.executable", aspell,
    119159            "The program 'aspell' is required for the live spell checker."), gbc);
    120160    gbc.gridy++;
    121     cp.add(createProgramPanel("PdfLatex", "compiler.pdflatex.executable", pdfLatex,
     161    main.add(new ProgramPanel("PdfLatex", "compiler.pdflatex.executable", pdfLatex,
    122162            "The program 'pdflatex' is required for generating PDF files."), gbc);
    123163    gbc.gridy++;
    124     cp.add(createProgramPanel("Latex", "compiler.latex.executable", latex,
     164    main.add(new ProgramPanel("Latex", "compiler.latex.executable", latex,
    125165            "The program 'latex' is required for generating DVI files."), gbc);
    126166    gbc.gridy++;
    127     cp.add(createProgramPanel("BibTex", "compiler.bibtex.executable", bibtex,
     167    main.add(new ProgramPanel("DviPs", "compiler.dvips.executable", dvips,
     168            "The program 'dvips' is required for converting DVI files to PS files."), gbc);
     169    gbc.gridy++;
     170    main.add(new ProgramPanel("Ps2Pdf", "compiler.ps2pdf.executable", ps2pdf,
     171            "The program 'ps2pdf' is required for converting PS files to PDF files."), gbc);
     172    gbc.gridy++;
     173    main.add(new ProgramPanel("BibTex", "compiler.bibtex.executable", bibtex,
    128174            "The program 'bibtex' is required for managing references."), gbc);
     175
     176    if(OS == OS_LINUX) {
     177      toolLocations.put("xdvi" , new ArrayList<File>());
     178      toolLocations.put("kdvi" , new ArrayList<File>());
     179      toolLocations.put("okular" , new ArrayList<File>());
     180    } else
     181    if(OS == OS_MAC) {
     182      toolLocations.put("Skim" , new ArrayList<File>());
     183    } else
     184    if(OS == OS_WINDOWS) {
     185      toolLocations.put("SumatraPDF" , new ArrayList<File>());
     186    }
     187
     188    gbc.gridy++;
     189    main.add(new ParameterisedProgramPanel(
     190            "PDF/DVI Viewer", "forward search.viewer", viewer,
     191            "<html>" +
     192            "This configuration is required for synchronization between the editor<br>" +
     193            "and your preferred viewer. Pressing `control shift F' in the editor will<br>" +
     194            "prompt the viewer to display the part that corresponds to the current<br>" +
     195            "position in the editor. The `prompting' is done by executing the<br>" +
     196             "command provided here." +
     197            "</html>",
     198            viewerParameters,
     199            "<html>" +
     200            "The viewer will be passed the following parameters:<br>" +
     201            "<ul>" +
     202            "<li>%file (the PDF or DVI file)</li>" +
     203            "<li>%texfile (the current source file), and</li>" +
     204            "<li>%line (the current source line).</li>" +
     205            "</html>"),
     206            gbc);
    129207
    130208    setModal(true);
     
    138216    // guessing suitable properties file
    139217    if(!GProperties.hasChanges()) {
    140       String osName= System.getProperty("os.name");
    141       if(osName != null && osName.equals("Mac OS X")) {
    142         keyStrokesList.setSelectedIndex(1);
    143       }
     218      if(OS == OS_MAC) keyStrokesList.setSelectedIndex(1);
     219      if(OS == OS_WINDOWS) keyStrokesList.setSelectedIndex(3);
    144220    }
    145221
     
    148224  }
    149225
    150   private JPanel createProgramPanel(String title, String executable, JTextField textField, String message) {
    151     JPanel panel = new JPanel(new BorderLayout());
    152     panel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), title));
    153 
    154     textField.setText(GProperties.getString(executable));
    155     panel.add(textField, BorderLayout.CENTER);
    156 
    157     JButton button = new JButton("...");
    158     panel.add(button, BorderLayout.EAST);
    159 
    160     textField.setText(GProperties.getString(executable));
    161     panel.add(new JLabel(message), BorderLayout.NORTH);
    162 
    163     JLabel resultLabel = new JLabel();
    164     panel.add(resultLabel, BorderLayout.SOUTH);
    165 
    166     final ExecutableChecker checker = new ExecutableChecker(textField, resultLabel);
    167     checker.run();
    168 
    169     textField.getDocument().addDocumentListener(new DocumentListener() {
    170       public void insertUpdate(DocumentEvent e) {
    171         check();
     226  private static class ProgramPanel extends JPanel {
     227    private String programName;
     228    private String gproperty;
     229
     230    private JLabel messageLabel;
     231    private JComboBox fileBox;
     232    private JButton openButton;
     233    private JLabel resultLabel;
     234
     235    private ExecutableChecker checker;
     236
     237    public ProgramPanel(String title, String gproperty, JComboBox fileBox, String message) {
     238      this(title, gproperty, fileBox, message, true);
     239    }
     240
     241
     242    public ProgramPanel(String title, String gproperty, JComboBox fileBox, String message, boolean layout) {
     243      this.programName = title.toLowerCase();
     244      if(OS == OS_WINDOWS) programName = programName + ".exe";
     245      this.gproperty = gproperty;
     246      this.fileBox = fileBox;
     247
     248      TitledBorder border = new TitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), title);
     249      border.setTitleFont(border.getTitleFont().deriveFont(Font.BOLD));
     250      setBorder(border);
     251
     252      ComboBoxEditor editor = fileBox.getEditor();
     253      DefaultComboBoxModel model = new DefaultComboBoxModel();
     254      fileBox.setEditable(true);
     255      fileBox.setModel(model);
     256
     257      String file = GProperties.getString(gproperty);
     258      if(OS == OS_WINDOWS && !file.toLowerCase().endsWith(".exe")) {
     259        file = file + ".exe";
     260        GProperties.set(gproperty, file);
    172261      }
    173262
    174       public void removeUpdate(DocumentEvent e) {
    175         check();
    176       }
    177 
    178       public void changedUpdate(DocumentEvent e) {
    179         check();
    180       }
    181 
    182       private void check() {
    183         SwingUtilities.invokeLater(checker);
    184       }
    185     });
    186 
    187     return panel;
     263      model.addElement(file);
     264      editor.setItem(file);
     265
     266      messageLabel = new JLabel(message);
     267      openButton = new JButton("...");
     268      resultLabel = new JLabel();
     269
     270      checker = new ExecutableChecker(fileBox, resultLabel);
     271      checker.run();
     272
     273      editor.addActionListener(new ActionListener() {
     274        @Override
     275        public void actionPerformed(ActionEvent e) {
     276          check();
     277        }
     278      });
     279
     280      fileBox.addItemListener(new ItemListener() {
     281        @Override
     282        public void itemStateChanged(ItemEvent e) {
     283          check();
     284        }
     285      });
     286
     287      if(layout) setupLayout();
     288    }
     289
     290    protected void setupLayout() {
     291      setLayout(new BorderLayout());
     292
     293      add(fileBox, BorderLayout.CENTER);
     294      add(openButton, BorderLayout.EAST);
     295      add(messageLabel, BorderLayout.NORTH);
     296      add(resultLabel, BorderLayout.SOUTH);
     297    }
     298
     299    public String getGproperty() {
     300      return gproperty;
     301    }
     302
     303    public String getProgramName() {
     304      return programName;
     305    }
     306
     307    private void check() {
     308      SwingUtilities.invokeLater(checker);
     309    }
     310  }
     311
     312  private static class ParameterisedProgramPanel extends ProgramPanel {
     313    protected JTextField parameterField;
     314    protected JLabel parameterMessageLabel;
     315
     316    public ParameterisedProgramPanel(String title, String gproperty, JComboBox fileBox, String message, JTextField parameterField, String parameterMessage) {
     317      super(title, gproperty, fileBox, message, false);
     318
     319      this.parameterField = parameterField;
     320      parameterMessageLabel = new JLabel(parameterMessage);
     321    }
    188322  }
    189323
     
    213347  }
    214348
    215   private class ExecutableChecker implements Runnable {
    216     private JTextField textField;
     349  private static class ExecutableChecker implements Runnable {
     350    private JComboBox comboBox;
    217351    private JLabel resultLabel;
    218352
    219     private ExecutableChecker(JTextField textField, JLabel resultLabel) {
    220       this.textField = textField;
     353    private static String[] PATH;
     354    static {
     355      String path = System.getenv("PATH");
     356      if(path == null) path = System.getenv("Path");
     357      if(path == null) path = System.getenv("path");
     358      if(path == null) path = "";
     359
     360      PATH = path.split(File.pathSeparator);
     361    }
     362
     363    private ExecutableChecker(JComboBox comboBox, JLabel resultLabel) {
     364      this.comboBox = comboBox;
    221365      this.resultLabel = resultLabel;
    222366    }
    223367
    224368    public void run() {
    225       String path = textField.getText();
    226 
    227       boolean success = true;
    228       try {
    229         File dir = SCEManager.getInstance().getMainEditor().getFile().getParentFile();
    230         Process process = ProcessUtil.exec(path, dir);
    231         process.destroy();
    232       } catch (Throwable e) {
    233         success = false;
    234       }
    235 
    236       if(success) {
     369      String path = comboBox.getEditor().getItem().toString();
     370
     371      if(checkExecutable(path)) {
    237372        resultLabel.setText("<html><font color=green>File found.</font></html>");
    238373      } else {
    239374        resultLabel.setText("<html><font color=red><bf>File not found.</bf></font></html>");
    240375      }
     376    }
     377
     378    public static boolean checkExecutable(String executable) {
     379      File file = new File(executable);
     380      if(file.exists() && file.canExecute()) return true;
     381
     382      for(String dirName : PATH) {
     383        File dir = new File(dirName);
     384        if(!dir.exists()) continue;
     385
     386        file = new File(dir, executable);
     387        if(file.exists() && file.canExecute()) return true;
     388      }
     389
     390      return false;
    241391    }
    242392  }
     
    294444    }
    295445  }
     446
     447  public static class ProgramWithParameters {
     448    private String name;
     449    private String executable;
     450    private String parameters;
     451
     452    public ProgramWithParameters(String name, String executable, String parameters) {
     453      this.name = name;
     454      this.executable = executable;
     455      this.parameters = parameters;
     456    }
     457
     458    public String getName() {
     459      return name;
     460    }
     461
     462    public void setName(String name) {
     463      this.name = name;
     464    }
     465
     466    public String getExecutable() {
     467      return executable;
     468    }
     469
     470    public void setExecutable(String executable) {
     471      this.executable = executable;
     472    }
     473
     474    public String getParameters() {
     475      return parameters;
     476    }
     477
     478    public void setParameters(String parameters) {
     479      this.parameters = parameters;
     480    }
     481  }
    296482}
Note: See TracChangeset for help on using the changeset viewer.