Changeset 1093


Ignore:
Timestamp:
Jun 23, 2011, 2:02:30 PM (6 years ago)
Author:
joerg
Message:
 
Location:
trunk/src
Files:
5 edited

Legend:

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

    r1088 r1093  
    13751375          if (choice == 0) save(editor);
    13761376          if (choice == 1) reload = true;
     1377          if (choice == 2) lastModified.put(file,  newModified);
    13771378        } else {
    13781379          reload = true;
  • trunk/src/jlatexeditor/SCEManager.java

    r1071 r1093  
    127127
    128128    if (program.equals("aspell")) {
    129       // set executables
    130       Aspell.ASPELL_EXECUTABLE = GProperties.getString("aspell.executable");
    131 
    132129      SpellChecker spellChecker = Aspell.getInstance(GProperties.getAspellLang());
    133130      if (spellChecker == null) throw new Exception("Initialization of the spell checker failed!");
  • trunk/src/jlatexeditor/gproperties/GProperties.java

    r1071 r1093  
    8383    String[] MONOSPACE_FONTS_ARRAY = new String[monospaceFonts.size()];
    8484    monospaceFonts.toArray(MONOSPACE_FONTS_ARRAY);
     85
     86    // set executables
     87    load();
     88    Aspell.ASPELL_EXECUTABLE = GProperties.getString("aspell.executable");
    8589
    8690    List<String> dictList;
     
    296300
    297301  private static void extractProperties() {
    298     editorFont = new Font(properties.getProperty(EDITOR_FONT_NAME), Font.PLAIN, properties.getInt(EDITOR_FONT_SIZE));
    299     textAntiAliasing = TEXT_ANTIALIAS_MAP.get(properties.getProperty(EDITOR_FONT_ANTIALIASING));
     302    try {
     303      editorFont = new Font(properties.getProperty(EDITOR_FONT_NAME), Font.PLAIN, properties.getInt(EDITOR_FONT_SIZE));
     304      textAntiAliasing = TEXT_ANTIALIAS_MAP.get(properties.getProperty(EDITOR_FONT_ANTIALIASING));
     305    } catch (NumberFormatException e) {
     306    }
    300307  }
    301308
     
    312319  }
    313320
     321  /**
     322   * Checks whether there are user changes.
     323   */
     324  public static boolean hasChanges() {
     325    for(BetterProperties2.Entry entry : properties.getEntries()) {
     326      if(!(entry instanceof Def)) continue;
     327
     328
     329      Def def = (Def) entry;
     330      String key = def.getKey();
     331      String currValue = properties.getProperty(key);
     332      String defValue = def.getValue();
     333
     334      if(currValue != null && !currValue.equals(defValue)) return true;
     335    }
     336
     337    return false;
     338  }
     339
     340  /**
     341   * Returns the underlying properties.
     342   */
     343  public static BetterProperties2 getProperties() {
     344    return properties;
     345  }
    314346
    315347  public static ArrayList<String> getMonospaceFonts() {
  • trunk/src/jlatexeditor/gui/Wizard.java

    r1071 r1093  
    11package jlatexeditor.gui;
    22
     3import de.endrullis.utils.BetterProperties2;
    34import jlatexeditor.SCEManager;
    45import jlatexeditor.gproperties.GProperties;
    5 import sce.codehelper.CHCommand;
    66import util.ProcessUtil;
     7import util.StreamUtils;
    78
    89import javax.swing.*;
     
    1213import javax.swing.event.DocumentListener;
    1314import java.awt.*;
    14 import java.io.File;
    15 import java.io.IOException;
    16 
    17 public class Wizard extends JDialog {
     15import java.awt.event.WindowEvent;
     16import java.awt.event.WindowListener;
     17import java.io.*;
     18import java.sql.Array;
     19import java.util.ArrayList;
     20import java.util.HashMap;
     21
     22public class Wizard extends JDialog implements WindowListener {
    1823  private String message =
    1924          "<font size=+2><bf>Welcome to JLatexEditor!</bf></font><br><br> " +
     
    2126          "and external tools.";
    2227
     28  private HashMap<String,ArrayList<File>> toolLocations = new HashMap<String, ArrayList<File>>();
     29  {{
     30    toolLocations.put("aspell" , new ArrayList<File>());
     31    toolLocations.put("pdflatex" , new ArrayList<File>());
     32    toolLocations.put("latex" , new ArrayList<File>());
     33    toolLocations.put("bibtex" , new ArrayList<File>());
     34  }}
     35
    2336  private JTextField aspell = new JTextField();
    2437  private JTextField pdfLatex = new JTextField();
    2538  private JTextField latex = new JTextField();
    2639  private JTextField bibtex = new JTextField();
     40
     41  private String[][] importantKeyStrokes = new String[][] {
     42          new String[] {"open", "Open File"},
     43          new String[] {"save", "Save File"},
     44          new String[] {"close", "Close Current Tab"},
     45          new String[] {"undo", "Undo"},
     46          new String[] {"find", "Find"},
     47          new String[] {"copy", "Copy"},
     48          new String[] {"paste", "Past"},
     49          new String[] {"cut", "Cut"},
     50          new String[] {"jump left", "Jump Left"},
     51          new String[] {"jump right", "Jump Right"},
     52          new String[] {"pdf", "Compile: pdflatex + bibtex"},
     53  };
     54
     55  private DefaultComboBoxModel keyStrokesListModel = new DefaultComboBoxModel();
     56  private JComboBox keyStrokesList = new JComboBox(keyStrokesListModel);
     57  private JButton showKeyStrokes = new JButton("Show");
     58
     59  private SearchToolsThread searchThread = new SearchToolsThread();
    2760
    2861  public Wizard(JFrame owner) {
     
    4679    gbc.weightx = 1; gbc.weighty = .2;
    4780
     81    JPanel keystrokesPanel = new JPanel(new BorderLayout());
     82    keystrokesPanel.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
     83            "Select KeyStroke Settings"));
     84
     85    if(GProperties.hasChanges()) {
     86      keyStrokesListModel.addElement(new KeyStrokeSettings("Keep My Current Settings", (BetterProperties2) GProperties.getProperties().clone()));
     87    }
     88
     89    for(int nr = 1; ; nr++) {
     90      try {
     91        String fileName = "data/configs/global.properties." + nr;
     92
     93        // read properties
     94        InputStream propertiesIn = StreamUtils.getInputStream(fileName);
     95        BetterProperties2 properties = new BetterProperties2(GProperties.getProperties());
     96        properties.load(propertiesIn);
     97        propertiesIn.close();
     98
     99        // read name
     100        InputStream nameIn = StreamUtils.getInputStream(fileName);
     101        BufferedReader nameReader = new BufferedReader(new InputStreamReader(nameIn));
     102        String name = nameReader.readLine().substring(1).trim();
     103        nameReader.close();
     104        nameIn.close();
     105
     106        keyStrokesListModel.addElement(new KeyStrokeSettings(name, properties));
     107      } catch (FileNotFoundException e) {
     108        break;
     109      } catch (IOException e) {
     110      }
     111    }
     112    keystrokesPanel.add(keyStrokesList, BorderLayout.CENTER);
     113
     114    gbc.gridy++;
     115    cp.add(keystrokesPanel, gbc);
     116
    48117    gbc.gridy++;
    49118    cp.add(createProgramPanel("Aspell", "aspell.executable", aspell,
     
    61130    setModal(true);
    62131    pack();
     132
     133    // guessing suitable properties file
     134    if(!GProperties.hasChanges()) {
     135      String osName= System.getProperty("os.name");
     136      if(osName != null && osName.equals("Mac OS X")) {
     137        keyStrokesList.setSelectedIndex(1);
     138      }
     139    }
     140
     141    // search for tools
     142    searchThread.start();
    63143  }
    64144
     
    101181
    102182    return panel;
     183  }
     184
     185  /**
     186   * WindowListener.
     187   */
     188  public void windowOpened(WindowEvent e) {
     189  }
     190
     191  public void windowClosing(WindowEvent e) {
     192  }
     193
     194  public void windowClosed(WindowEvent e) {
     195    searchThread.stop();
     196  }
     197
     198  public void windowIconified(WindowEvent e) {
     199  }
     200
     201  public void windowDeiconified(WindowEvent e) {
     202  }
     203
     204  public void windowActivated(WindowEvent e) {
     205  }
     206
     207  public void windowDeactivated(WindowEvent e) {
    103208  }
    104209
     
    131236    }
    132237  }
     238
     239  private static class KeyStrokeSettings {
     240    private String name;
     241    private BetterProperties2 settings;
     242
     243    private KeyStrokeSettings(String name, BetterProperties2 settings) {
     244      this.name = name;
     245      this.settings = settings;
     246    }
     247
     248    public String getName() {
     249      return name;
     250    }
     251
     252    public BetterProperties2 getSettings() {
     253      return settings;
     254    }
     255
     256    @Override
     257    public String toString() {
     258      return name;
     259    }
     260  }
     261
     262  private class SearchToolsThread extends Thread {
     263    ArrayList<String> toolNames = new ArrayList<String>(toolLocations.keySet());
     264
     265    @Override
     266    public void run() {
     267      setPriority(Thread.MIN_PRIORITY);
     268      searchTools(new File("/"), 0);
     269      searchTools(new File("C:\\"), 0);
     270      searchTools(new File("D:\\"), 0);
     271    }
     272
     273    private void searchTools(File dir, int depth) {
     274      if(depth > 5 || !dir.isDirectory()) return;
     275
     276      File files[] = dir.listFiles();
     277      if(files == null) return;
     278
     279      for(File file : files) {
     280        searchTools(file, depth+1);
     281
     282        for(String name : toolNames) {
     283          File executable = new File(dir, name);
     284          if(executable.exists() && executable.isFile() && executable.canExecute()) {
     285            toolLocations.get(name).add(executable);
     286          }
     287        }
     288      }
     289    }
     290  }
    133291}
  • trunk/src/util/Aspell.java

    r1025 r1093  
    22
    33import de.endrullis.utils.StringUtils;
     4import jlatexeditor.gproperties.GProperties;
    45
    56import java.io.*;
Note: See TracChangeset for help on using the changeset viewer.