Skip to content

Commit

Permalink
Few corrections in the user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mmpcn committed Feb 27, 2014
1 parent 5516f12 commit 98a89b0
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 deletions splat/src/main/uk/ac/starlink/splat/vo/SSAServerTree.java
Expand Up @@ -40,6 +40,7 @@
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
Expand Down Expand Up @@ -230,7 +231,8 @@ public SSAServerTree( SSAServerList serverList, ServerParamRelation spr )
//setSSAServerList( serverList );
}





/**
* Initialise the main part of the user interface.
Expand Down Expand Up @@ -389,10 +391,8 @@ protected void initUI()
src_theo.addItemListener(checkBoxlistener);
treeRenderer.addSrc(src_theo.getText());
src_inv = new JCheckBox("Invisible"); // so I can uncheck both theo/obs if I need
ButtonGroup group = new ButtonGroup();
group.add(src_obs);
group.add(src_theo);
group.add(src_inv);


c.weightx=1;
c.gridy = 0;

Expand Down Expand Up @@ -1203,6 +1203,9 @@ protected void addNewServer()
*/
protected void addNewTag()
{

boolean newTag = true;

// are there selected servers?
int nrSelected=serverTree.getSelectionCount();
if (nrSelected == 0) {
Expand All @@ -1212,12 +1215,31 @@ protected void addNewTag()
"No servers selected", JOptionPane.ERROR_MESSAGE );
return;
}

String tagname = (String)JOptionPane.showInputDialog ( this,"Enter Tagname:\n");
if (tagname == null || tagname.length() == 0) {
return;
}

if ( tagsListModel.contains(tagname)) {
//Custom button text
Object[] options = {"Overwrite",
"Add to existing tag",
"Cancel"};
int n = JOptionPane.showOptionDialog(this,"The tag "+ tagname+ " exists already.\n",
" ",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);

if (n == JOptionPane.YES_OPTION)
removeTag(tagname); // remove the old tag, create it again
else if ( n == JOptionPane.CANCEL_OPTION ) // add selected to existing tag
return;
else if (n == JOptionPane.NO_OPTION)
newTag = false; // the tags will be added to the existing tag
}

DefaultTreeModel model = (DefaultTreeModel) serverTree.getModel();
ServerTreeNode root = (ServerTreeNode) model.getRoot();
Expand All @@ -1237,26 +1259,31 @@ protected void addNewTag()
}

// JCheckBox tag = new JCheckBox(tagname);
tagsListModel.addElement(tagname);
tagsList.setSelectedValue(tagname, true);

treeRenderer.addTag(tagname);
tagsList.setSelectedValue(tagname, true);
if ( newTag ) {
tagsListModel.addElement(tagname);
treeRenderer.addTag(tagname);
}

this.repaint();

}

/**
* Add new tag to the server list
* Remove tag
*/

protected void removeTag()
{
// are there selected servers?


String tagname = tagsList.getSelectedValue().toString();
int index = tagsList.getSelectedIndex();
tagsListModel.remove(tagsList.getSelectedIndex());
removeTag(tagname);

}
protected void removeTag(String tagname) {
//
tagsListModel.removeElement(tagname);
//tagsListModel.remove(tagsList.getSelectedIndex());
//tagsListModel.remove(tagsListModel.getindex);

DefaultTreeModel model = (DefaultTreeModel) serverTree.getModel();
Expand All @@ -1276,7 +1303,7 @@ protected void removeTag()
e.printStackTrace();
}
this.repaint();
//to do save / reload user tags!!!!!!!!!!!!!!!!!!!

}

/**
Expand Down Expand Up @@ -1454,8 +1481,8 @@ public void addTag(String tag) {

}
public void addTag(String tag, boolean save) {
tags.add(tag);

tags.add(tag);
// save: TO DO
}

private boolean containsTag(String tag) {
Expand All @@ -1482,6 +1509,8 @@ protected ArrayList<String> getTags() {
return (tags);
}



public String toString() {

return getUserObject().toString();
Expand Down Expand Up @@ -1623,7 +1652,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
c.setForeground(Color.BLACK);
serverList.selectServer(shortname);
} else {
node.setSelected(false);
node.setSelected(false);
c.setForeground(Color.GRAY);
serverList.unselectServer(shortname);
}
Expand Down Expand Up @@ -1886,4 +1915,6 @@ public void componentResized(ComponentEvent e) {
updateUI();
}
}


}

0 comments on commit 98a89b0

Please sign in to comment.