From: <ber...@us...> - 2009-08-06 19:12:43
|
Revision: 15870 http://jedit.svn.sourceforge.net/jedit/?rev=15870&view=rev Author: berndbischl Date: 2009-08-06 19:12:33 +0000 (Thu, 06 Aug 2009) Log Message: ----------- missing options panel Added Paths: ----------- plugins/jeditr/trunk/com/addictedtor/jeditr/JEditROptionPane.java Added: plugins/jeditr/trunk/com/addictedtor/jeditr/JEditROptionPane.java =================================================================== --- plugins/jeditr/trunk/com/addictedtor/jeditr/JEditROptionPane.java (rev 0) +++ plugins/jeditr/trunk/com/addictedtor/jeditr/JEditROptionPane.java 2009-08-06 19:12:33 UTC (rev 15870) @@ -0,0 +1,140 @@ +package com.addictedtor.jeditr; + +import org.af.jhlir.tools.DirectoryGuesser; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.gjt.sp.jedit.AbstractOptionPane; +import org.gjt.sp.jedit.jEdit; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.Hashtable; + + +/** + * Options panel + * + * @author Bernd Bischl <ber...@gm...> + * @author Romain Francois <fra...@fr...> + */ + +public class JEditROptionPane extends AbstractOptionPane implements ActionListener { + protected static final Log logger = LogFactory.getLog(JEditROptionPane.class); + + public static final String OPTION_PREFIX = "options.jeditr."; + private Hashtable<String, JTextField> pathNames = new Hashtable<String, JTextField>(); + private JTextField tfRHome = new JTextField(); + private JTextField tfShortcut = new JTextField(); + + + public JEditROptionPane() { + super("jeditr-optionpane"); + } + + + public void _init() { + addPathPanel("rhome", tfRHome); + addPathPanel("shortcut", tfShortcut); + guessDirs(); + } + + private void addPathPanel(String name, JTextField tf) { + pathNames.put(name, tf); + addSeparator(OPTION_PREFIX + name + ".title"); + addComponent("", makePathPanel(name, tf)); + } + + private void guessDirs() { +// if (tfJavaHome.getText().trim().equals("")) +// tfJavaHome.setText(DirectoryGuesser.guessJavaHome()); + if (tfRHome.getText().trim().equals("")) { + String rHome = DirectoryGuesser.guessRHome(); + logger.info("Guessing R_HOME : " + rHome); + tfRHome.setText(rHome); + } + if (tfShortcut.getText().trim().equals("")) { + String desktop = DirectoryGuesser.guessDesktop(); + logger.info("Guessing shortcut dir : " + desktop); + tfShortcut.setText(desktop); + } + } + + private JPanel makePathPanel(String name, JTextField tf) { + tf.setText(jEdit.getProperty(OPTION_PREFIX + name + ".path")); + JButton pickPath = new JButton(jEdit.getProperty(OPTION_PREFIX + "choose-dir")); + pickPath.setActionCommand("choose-" + name); + JPanel pathPanel = new JPanel(new BorderLayout(0, 0)); + pathPanel.add(tf, BorderLayout.CENTER); + pathPanel.add(pickPath, BorderLayout.EAST); + pickPath.addActionListener(this); + return pathPanel; + } + + + + private void selectDir(String name) { + JFileChooser fc = new JFileChooser(); + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int res = fc.showOpenDialog(this); + if (res == JFileChooser.APPROVE_OPTION) { + String dir = fc.getSelectedFile().getAbsolutePath(); + pathNames.get(name).setText(dir); + } + } + + public void actionPerformed(ActionEvent e) { + String ac = e.getActionCommand(); + if (ac.startsWith("choose-")) { + selectDir(ac.substring(7)); + } + } + + + + public void _save() { + + logger.info("Saving options."); + + String rhome = tfRHome.getText(); + String javahome = System.getProperty("java.home"); + String shortcut = tfShortcut.getText(); + + File rhomeFile = new File(rhome); + File shortcutFile = new File(shortcut); + + String err = null; + if (!rhomeFile.exists() || !rhomeFile.isDirectory()) { + err = "R home directory does not exist or is not a proper directory!"; + } + if (!shortcutFile.exists() || !shortcutFile.isDirectory()) { + err = "Directory for shortcut does not exist or is not a proper directory!"; + } + + if (err != null) { + JOptionPane.showMessageDialog(this, err); + } else { + try { +// RCmdBatch rCmdBatch = new RCmdBatch(rhome); +// rCmdBatch.retrieveRInfo(); +// RPackage rp = rCmdBatch.getInstalledPackInfo("rJava"); + Installer i = new Installer( + jEdit.getJEditHome(), + JEditRPlugin.getInstance().getPluginHome().getAbsolutePath(), + rhome, +// rp.getLibpath().getAbsolutePath(), +// rCmdBatch.getLibPaths(), +// javahome, + shortcut + ); + i.install(); + } catch (Exception e) { + // todo handle + e.printStackTrace(); + } + } + logger.info("Saving options done."); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |