Skip to content
Snippets Groups Projects
Commit 74a592a4 authored by tcarver's avatar tcarver
Browse files

add more functionality

parent d0edcb8e
No related branches found
No related tags found
No related merge requests found
/* ProjectProperty.java /* ProjectProperty
* This file is part of Artemis * This file is part of Artemis
* *
* Copyright(C) 2012 Genome Research Limited * Copyright(C) 2012 Genome Research Limited
...@@ -21,12 +21,16 @@ ...@@ -21,12 +21,16 @@
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Properties; import java.util.Properties;
...@@ -36,10 +40,17 @@ import java.util.Set; ...@@ -36,10 +40,17 @@ import java.util.Set;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.DefaultListModel;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.Border; import javax.swing.border.Border;
...@@ -48,8 +59,18 @@ import javax.swing.event.ListSelectionEvent; ...@@ -48,8 +59,18 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import uk.ac.sanger.artemis.components.genebuilder.TextAreaDocumentListener; import uk.ac.sanger.artemis.components.genebuilder.TextAreaDocumentListener;
import uk.ac.sanger.artemis.util.Document;
import uk.ac.sanger.artemis.util.FileDocument;
class ProjectProperty extends JFrame /**
* Project file management system using a properties file.
*
* Example of the syntax for defining a project in the property file:
* project.Pknowlsei.ref = Pknowlsei:Pk_strainH_chr01
* project.Pknowlsei.chado = genedb-db.sanger.ac.uk:5432/snapshot?genedb_ro
* project.Pknowlsei.title = Pknowlsei
*/
public class ProjectProperty extends JFrame
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private HashMap<String, HashMap<String, String>> projects; private HashMap<String, HashMap<String, String>> projects;
...@@ -58,22 +79,63 @@ class ProjectProperty extends JFrame ...@@ -58,22 +79,63 @@ class ProjectProperty extends JFrame
private final static int ANNOTATION = 2; private final static int ANNOTATION = 2;
private final static int NEXT_GEN_DATA = 3; private final static int NEXT_GEN_DATA = 3;
private final static int CHADO = 4; private final static int CHADO = 4;
private static org.apache.log4j.Logger logger4j =
org.apache.log4j.Logger.getLogger(ProjectProperty.class);
private final static String[] TYPES =
{ "title", "ref", "annotation", "bam", "vcf", "chado" };
ProjectProperty() public ProjectProperty()
{ {
final InputStream ins = super("Project File Manager");
InputStream ins =
this.getClass().getClassLoader().getResourceAsStream("etc/project.properties"); this.getClass().getClassLoader().getResourceAsStream("etc/project.properties");
try
{
logger4j.debug("Reading properties from: "+
this.getClass().getClassLoader().getResource("etc/project.properties").toURI());
}
catch (URISyntaxException e1){}
final Properties projectProps = new Properties(); final Properties projectProps = new Properties();
try try
{ {
projectProps.load(ins); projectProps.load(ins);
ins.close(); ins.close();
projects = getProjectMap(projectProps);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
final String [] propFiles =
{
"project.properties",
System.getProperty("user.home") + File.separator + ".project.properties"
};
for(int i=0; i<propFiles.length; i++)
{
final Document doc =
new FileDocument(new File(propFiles[i]));
if(doc.readable())
{
try
{
ins = doc.getInputStream();
projectProps.load(ins);
}
catch (IOException e)
{
e.printStackTrace();
}
logger4j.debug("Reading properties from: "+propFiles[i]);
}
}
projects = getProjectMap(projectProps);
createProjectViewer((JPanel) getContentPane()); createProjectViewer((JPanel) getContentPane());
pack(); pack();
setVisible(true); setVisible(true);
...@@ -81,77 +143,189 @@ class ProjectProperty extends JFrame ...@@ -81,77 +143,189 @@ class ProjectProperty extends JFrame
private void createProjectViewer(JPanel panel) private void createProjectViewer(JPanel panel)
{ {
final DefaultListModel model = new DefaultListModel();
final JList projectList = new JList(model);
final JScrollPane jspList = new JScrollPane(projectList);
Object[] items = projects.keySet().toArray();
for (int i=0; i<items.length; i++)
model.add(i, items[i]);
final Box yBox = Box.createVerticalBox();
final LaunchActionListener listener = new LaunchActionListener();
projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
projectList.setVisibleRowCount(-1);
panel.add(jspList, BorderLayout.WEST);
panel.add(yBox, BorderLayout.CENTER);
// menus
final JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
final JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
final JMenuItem exitMenu = new JMenuItem("Exit");
fileMenu.add(exitMenu);
exitMenu.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
int status = JOptionPane.showConfirmDialog(
ProjectProperty.this, "Exit?", "Exit", JOptionPane.YES_NO_OPTION);
if(status == JOptionPane.YES_OPTION)
Splash.exitApp();
}
});
final JMenu editMenu = new JMenu("Edit");
menuBar.add(editMenu);
final JMenuItem addProject = new JMenuItem("Add Project");
addProject.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
String projName =
JOptionPane.showInputDialog(ProjectProperty.this,
"Project Name", "New Project", JOptionPane.QUESTION_MESSAGE);
if(projName == null)
return;
projects.put(projName, new HashMap<String, String>());
model.add(model.getSize(), projName);
projectList.repaint();
}
});
editMenu.add(addProject);
final JMenuItem removeProject = new JMenuItem("Remove Project");
removeProject.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
projects.remove(projectList.getSelectedValue());
model.remove(projectList.getSelectedIndex());
projectList.repaint();
yBox.removeAll();
yBox.repaint();
}
});
editMenu.add(removeProject);
//
panel.setPreferredSize(new Dimension(650,400)); panel.setPreferredSize(new Dimension(650,400));
panel.setBackground(Color.WHITE);
final JButton openArt = new JButton("OPEN"); final JButton openArt = new JButton("OPEN");
final LaunchActionListener listener = new LaunchActionListener();
openArt.addActionListener(listener); openArt.addActionListener(listener);
panel.add(openArt, BorderLayout.SOUTH); panel.add(openArt, BorderLayout.SOUTH);
final JList projectList = new JList(projects.keySet().toArray());
projectList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
panel.add(projectList, BorderLayout.WEST);
final GridBagConstraints c = new GridBagConstraints(); final GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTHWEST; c.anchor = GridBagConstraints.NORTHWEST;
c.fill = GridBagConstraints.VERTICAL; c.fill = GridBagConstraints.VERTICAL;
c.ipadx = 10; c.ipadx = 10;
c.ipady = 10; c.ipady = 10;
final Box props = Box.createVerticalBox();
projectList.addListSelectionListener(new ListSelectionListener() projectList.addListSelectionListener(new ListSelectionListener()
{ {
public void valueChanged(ListSelectionEvent e) public void valueChanged(ListSelectionEvent e)
{ {
if(e.getValueIsAdjusting() == false) if(e.getValueIsAdjusting() == false &&
projectList.getSelectedIndex() > -1)
refreshProperties(projectList, yBox, listener);
}
});
}
/**
* Refresh components in the properties panel.
* @param projectList
* @param yBox
* @param listener
*/
private void refreshProperties(final JList projectList,
final Box yBox,
final LaunchActionListener listener)
{
yBox.removeAll();
final HashMap<String, String> projProps = projects.get(projectList.getSelectedValue());
final HashMap<Integer, QualifierTextArea> settings = new HashMap<Integer, QualifierTextArea>();
for(final String key: projProps.keySet())
{
Box xBox = Box.createHorizontalBox();
final QualifierTextArea qta = new QualifierTextArea();
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
TitledBorder title = BorderFactory.createTitledBorder(
loweredbevel, key);
title.setTitlePosition(TitledBorder.ABOVE_TOP);
qta.setBorder(title);
qta.setText(projProps.get(key));
qta.getDocument().addDocumentListener(
new TextAreaDocumentListener(qta));
xBox.add(qta);
// REMOVE PROPERTY
final JButton removeProperty = new JButton("X");
removeProperty.setOpaque(false);
Font font = removeProperty.getFont().deriveFont(Font.BOLD);
removeProperty.setFont(font);
removeProperty.setToolTipText("REMOVE");
removeProperty.setForeground(new Color(139, 35, 35));
removeProperty.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
projProps.remove(key);
refreshProperties(projectList, yBox, listener);
}
});
xBox.add(removeProperty);
//
yBox.add(xBox);
if(key.equals("ref"))
settings.put(ProjectProperty.REFERENCE, qta);
else if(key.equals("annotation"))
settings.put(ProjectProperty.ANNOTATION, qta);
else if(key.equals("bam") || key.equals("vcf") || key.equals("bcf"))
settings.put(ProjectProperty.NEXT_GEN_DATA, qta);
else if(key.equals("chado"))
settings.put(ProjectProperty.CHADO, qta);
}
// ADD property
Box xBox = Box.createHorizontalBox();
final JButton addPropertyButton = new JButton("NEW PROPERTY");
final JComboBox propertyList = new JComboBox(TYPES);
xBox.add(addPropertyButton);
xBox.add(propertyList);
xBox.add(Box.createHorizontalGlue());
yBox.add(xBox);
addPropertyButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0)
{
String key = (String) propertyList.getSelectedItem();
if(!projProps.containsKey(key))
{ {
if(projectList.getSelectedIndex() > -1) projProps.put(key, "");
{ refreshProperties(projectList, yBox, listener);
props.removeAll();
final HashMap<String, String> projProps = projects.get(projectList.getSelectedValue());
final HashMap<Integer, QualifierTextArea> settings = new HashMap<Integer, QualifierTextArea>();
for(String key: projProps.keySet())
{
Box xBox = Box.createHorizontalBox();
final QualifierTextArea qta = new QualifierTextArea();
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
TitledBorder title = BorderFactory.createTitledBorder(
loweredbevel, key);
title.setTitlePosition(TitledBorder.ABOVE_TOP);
qta.setBorder(title);
qta.setText(projProps.get(key));
qta.getDocument().addDocumentListener(
new TextAreaDocumentListener(qta));
xBox.add(qta);
props.add(xBox);
if(key.equals("ref"))
settings.put(ProjectProperty.REFERENCE, qta);
else if(key.equals("annotation"))
settings.put(ProjectProperty.ANNOTATION, qta);
else if(key.equals("bam") || key.equals("vcf") || key.equals("bcf"))
settings.put(ProjectProperty.NEXT_GEN_DATA, qta);
else if(key.equals("chado"))
settings.put(ProjectProperty.CHADO, qta);
}
props.add(Box.createVerticalGlue());
props.revalidate();
props.repaint();
listener.setSettings(settings);
}
} }
} }
}); });
panel.add(props, BorderLayout.CENTER); //
yBox.add(Box.createVerticalGlue());
yBox.revalidate();
yBox.repaint();
listener.setSettings(settings);
} }
/** /**
* Create a project hash of the properties. * Create a project hash of the properties.
* @param projectProps * @param projectProps
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment