From 9785ea7bda295b20215f0da9cc0382e060854a75 Mon Sep 17 00:00:00 2001 From: josch Date: Wed, 19 Jan 2011 18:27:32 +0200 Subject: [PATCH] add preferences pane --- META-INF/MANIFEST.MF | 3 +- plugin.xml | 20 ++-- .../hets/protege/HetsPreferences.java | 49 ++++++++++ .../hets/protege/HetsPreferencesPane.java | 91 +++++++++++++++++++ 4 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 src/de/unibremen/informatik/hets/protege/HetsPreferences.java create mode 100644 src/de/unibremen/informatik/hets/protege/HetsPreferencesPane.java diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index cbf316c..8dd16e7 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Import-Package: org.osgi.framework;version="1.3.0", org.protege.owlapi.apibinding, org.protege.owlapi.model, org.semanticweb.owlapi.model, - javax.swing + javax.swing, + javax.swing.border Require-Bundle: org.eclipse.equinox.registry, org.eclipse.equinox.common, org.protege.common;bundle-version="4.1.0", diff --git a/plugin.xml b/plugin.xml index 9a42274..178f114 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,9 +1,8 @@ - + @@ -11,9 +10,8 @@ - + @@ -21,13 +19,17 @@ - + + + diff --git a/src/de/unibremen/informatik/hets/protege/HetsPreferences.java b/src/de/unibremen/informatik/hets/protege/HetsPreferences.java new file mode 100644 index 0000000..bc6f400 --- /dev/null +++ b/src/de/unibremen/informatik/hets/protege/HetsPreferences.java @@ -0,0 +1,49 @@ +package de.unibremen.informatik.hets.protege; + +import org.protege.editor.core.prefs.Preferences; +import org.protege.editor.core.prefs.PreferencesManager; + +public class HetsPreferences { + private static HetsPreferences instance; + + private static final String KEY = "de.unibremen.informatik.hets"; + + private static final String DEFAULT_MAC_PATH = "/usr/local/Hets/bin/hets"; + private static final String DEFAULT_WINDOWS_PATH = "C:\\Program Files\\Hets\\bin\\hets"; + private static final String DEFAULT_LINUX_PATH = "/usr/bin/hets"; + + private static final String HETSPATH = "HETSPATH"; + + public static synchronized HetsPreferences getInstance() { + if(instance == null) { + instance = new HetsPreferences(); + } + return instance; + } + + private Preferences getPrefs() { + return PreferencesManager.getInstance().getApplicationPreferences(KEY); + } + + private static String getDefaultPath() { + String platform = System.getProperty("os.name"); + + if(platform.indexOf("OS X") != -1) { + return DEFAULT_MAC_PATH; + } + else if(platform.indexOf("Windows") != -1) { + return DEFAULT_WINDOWS_PATH; + } + else { + return DEFAULT_LINUX_PATH; + } + } + + public String getHetsPath() { + return getPrefs().getString(HETSPATH, getDefaultPath()); + } + + public void setHetsPath(String path) { + getPrefs().putString(HETSPATH, path); + } +} diff --git a/src/de/unibremen/informatik/hets/protege/HetsPreferencesPane.java b/src/de/unibremen/informatik/hets/protege/HetsPreferencesPane.java new file mode 100644 index 0000000..46f6f06 --- /dev/null +++ b/src/de/unibremen/informatik/hets/protege/HetsPreferencesPane.java @@ -0,0 +1,91 @@ +package de.unibremen.informatik.hets.protege; + +import de.unibremen.informatik.hets.protege.HetsPreferences; + +import org.protege.editor.core.ui.util.UIUtil; +import org.protege.editor.owl.ui.preferences.OWLPreferencesPanel; + +import java.util.ArrayList; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; + +public class HetsPreferencesPane extends OWLPreferencesPanel { + + private java.util.List optionPages = new ArrayList(); + + public void applyChanges() { + for (OWLPreferencesPanel optionPage : optionPages) { + optionPage.applyChanges(); + } + } + + public void initialise() throws Exception { + setLayout(new BorderLayout()); + + OWLPreferencesPanel foo = new Foobar(); + OWLPreferencesPanel bar = new Foobar(); + OWLPreferencesPanel baz = new Foobar(); + + JTabbedPane tabPane = new JTabbedPane(); + + Box box = new Box(BoxLayout.Y_AXIS); + box.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); + box.add(foo); + box.add(Box.createVerticalStrut(7)); + box.add(bar); + box.add(Box.createVerticalStrut(7)); + box.add(baz); + + tabPane.add("General Options", box); + + optionPages.add(foo); + optionPages.add(bar); + optionPages.add(baz); + + foo.initialise(); + bar.initialise(); + baz.initialise(); + + add(tabPane, BorderLayout.NORTH); + } + + public void dispose() throws Exception { + for (OWLPreferencesPanel optionPage : optionPages) { + optionPage.dispose(); + } + } + + class Foobar extends OWLPreferencesPanel { + private JTextField pathField; + + public void applyChanges() { + HetsPreferences.getInstance().setHetsPath(pathField.getText()); + } + + public void initialise() throws Exception { + setLayout(new BorderLayout(12, 12)); + + setBorder(BorderFactory.createTitledBorder("Dot Application Path")); + + Box panel = new Box(BoxLayout.LINE_AXIS); + + pathField = new JTextField(15); + pathField.setText(HetsPreferences.getInstance().getHetsPath()); + + JButton browseButton = new JButton(new AbstractAction("Browse") { + public void actionPerformed(ActionEvent e) { + } + }); + + panel.add(new JLabel("Path:")); + panel.add(pathField); + panel.add(browseButton); + + add(panel); + } + + public void dispose() throws Exception { + } + } +}