package trust.jfcm.gui;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Event;
import java.awt.BorderLayout;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.KeyStroke;
import java.awt.Point;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JMenuItem;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JFrame;
import javax.swing.JDialog;
import javax.swing.UIManager;
import java.awt.GridBagLayout;
import javax.swing.BoxLayout;
import java.awt.GridBagConstraints;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.Insets;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.awt.ComponentOrientation;
import javax.swing.JTextPane;
import javax.swing.filechooser.FileFilter;
import trust.jfcm.CognitiveMap;
import trust.jfcm.FcmConnection;
import trust.jfcm.utils.FcmIO;
import java.awt.SystemColor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
public class MapEditor {
public static JFrame jFrame = null; // @jve:decl-index=0:visual-constraint="10,10"
private JPanel jContentPane = null;
private JMenuBar jJMenuBar = null;
private JMenu fileMenu = null;
private JMenu editMenu = null;
private JMenu helpMenu = null;
private JMenuItem exitMenuItem = null;
private JMenuItem aboutMenuItem = null;
private JMenuItem cutMenuItem = null;
private JMenuItem copyMenuItem = null;
private JMenuItem pasteMenuItem = null;
private JMenuItem saveMenuItem = null;
private JMenuItem openMenuItem = null;
private JDialog aboutDialog = null;
private JPanel aboutContentPane = null;
private JLabel aboutVersionLabel = null;
private JPanel jPanelRight = null;
private JPanel jPanelLeft = null;
private JLabel Head = null;
private JLabel Concepts = null;
private JLabel Insert = null;
private JTextField conceptText = null;
private JLabel Relations = null;
private JButton SaveButton = null;
private JLabel InsertLink = null;
private JComboBox jComboBoxCausalLinksFrom = null;
private JLabel mapsText = null;
private JLabel mapListText = null;
private JButton SaveButtonLink = null;
private JLabel jLabelWeight = null;
private JTextField jTextFieldWeight = null;
private JLabel InLinks = null;
private JTextPane InTextLinks = null;
private JTextPane OutTextLinks = null;
private JLabel OutLinks = null;
private JComboBox jComboBoxCausalLinksTo = null;
private JLabel Text = null;
private JLabel Text1 = null;
private JFileChooser chooser = null;
private JComboBox jComboBoxMapList = null;
private JLabel Relations1 = null;
private JLabel SelectConcepts = null;
private JComboBox jComboBoxMapConcepts = null;
private Map<String, CognitiveMap> maps = null; // @jve:decl-index=0:
private String[] mapList = null;
private JLabel HeadRight = null;
//private JGraph2DViewer jgraphViewer;
private Jung2DViewer jungViewer;
/**
* This method initializes jFrame
*
* @return javax.swing.JFrame
*/
private JFrame getJFrame() {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(930, 685);
jFrame.setContentPane(getJContentPane());
jFrame.setTitle("Map Editor");
}
return jFrame;
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BoxLayout(getJContentPane(), BoxLayout.X_AXIS));
jContentPane.add(getJPanelLeft(), null);
jContentPane.add(getJPanelRight(), null);
}
return jContentPane;
}
/**
* This method initializes jJMenuBar
*
* @return javax.swing.JMenuBar
*/
private JMenuBar getJJMenuBar() {
if (jJMenuBar == null) {
jJMenuBar = new JMenuBar();
jJMenuBar.add(getFileMenu());
jJMenuBar.add(getEditMenu());
jJMenuBar.add(getHelpMenu());
}
return jJMenuBar;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText("File");
fileMenu.add(getOpenMenuItem());
fileMenu.add(getSaveMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getEditMenu() {
if (editMenu == null) {
editMenu = new JMenu();
editMenu.setText("Edit");
editMenu.add(getCutMenuItem());
editMenu.add(getCopyMenuItem());
editMenu.add(getPasteMenuItem());
}
return editMenu;
}
/**
* This method initializes jMenu
*
* @return javax.swing.JMenu
*/
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText("Help");
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
return exitMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog aboutDialog = getAboutDialog();
aboutDialog.pack();
Point loc = getJFrame().getLocation();
loc.translate(20, 20);
aboutDialog.setLocation(loc);
aboutDialog.setVisible(true);
}
});
}
return aboutMenuItem;
}
/**
* This method initializes aboutDialog
*
* @return javax.swing.JDialog
*/
private JDialog getAboutDialog() {
if (aboutDialog == null) {
aboutDialog = new JDialog(getJFrame(), true);
aboutDialog.setTitle("About");
aboutDialog.setContentPane(getAboutContentPane());
}
return aboutDialog;
}
/**
* This method initializes aboutContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getAboutContentPane() {
if (aboutContentPane == null) {
aboutContentPane = new JPanel();
aboutContentPane.setLayout(new BorderLayout());
aboutContentPane.add(getAboutVersionLabel(), BorderLayout.CENTER);
}
return aboutContentPane;
}
/**
* This method initializes aboutVersionLabel
*
* @return javax.swing.JLabel
*/
private JLabel getAboutVersionLabel() {
if (aboutVersionLabel == null) {
aboutVersionLabel = new JLabel();
aboutVersionLabel.setText("Version 1.0");
aboutVersionLabel.setHorizontalAlignment(SwingConstants.CENTER);
}
return aboutVersionLabel;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCutMenuItem() {
if (cutMenuItem == null) {
cutMenuItem = new JMenuItem();
cutMenuItem.setText("Cut");
cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
Event.CTRL_MASK, true));
cutMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//String selection = conceptText.getSelectedText();
//StringSelection data = new StringSelection(selection);
//clipboard.setContents(data, null);
conceptText.cut();
}
});
}
return cutMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getCopyMenuItem() {
if (copyMenuItem == null) {
copyMenuItem = new JMenuItem();
copyMenuItem.setText("Copy");
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
Event.CTRL_MASK, true));
copyMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
conceptText.copy();
}
});
}
return copyMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getPasteMenuItem() {
if (pasteMenuItem == null) {
pasteMenuItem = new JMenuItem();
pasteMenuItem.setText("Paste");
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
Event.CTRL_MASK, true));
pasteMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
conceptText.paste();
}
});
}
return pasteMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getSaveMenuItem() {
if (saveMenuItem == null) {
saveMenuItem = new JMenuItem();
saveMenuItem.setText("Save");
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Event.CTRL_MASK, true));
saveMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Create a file chooser
if(chooser == null){
String filename = File.separator+"tmp";
chooser = new JFileChooser(new File(filename));
// Create file filter
FileFilter xmlFilter = null;
chooser.addChoosableFileFilter(xmlFilter);
}
// Show dialog; this method does not return until dialog is closed
chooser.showSaveDialog(getJFrame());
}
});
}
return saveMenuItem;
}
/**
* This method initializes jMenuItem
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getOpenMenuItem() {
if (openMenuItem == null) {
openMenuItem = new JMenuItem();
openMenuItem.setText("Open");
openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
Event.CTRL_MASK, true));
openMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Create a file chooser
if(chooser == null){
String filename = File.separator+"tmp";
chooser = new JFileChooser(new File(filename));
// Create file filter
FileFilter xmlFilter = null;
chooser.addChoosableFileFilter(xmlFilter);
chooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
parseFile();
}
});
}
// Show dialog; this method does not return until dialog is closed
chooser.showOpenDialog(getJFrame());
}
});
}
return openMenuItem;
}
private void parseFile(){
File file = chooser.getSelectedFile();
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
maps = FcmIO.loadMapFromXml(inputStream);
System.out.println(maps);
mapList = (String[]) maps.keySet().toArray(new String[0]);
System.out.println(mapList);
//set JComboBoxes
for (String mapName : mapList){
jComboBoxMapList.addItem(mapName);
}
System.out.println("Item:" + jComboBoxMapList.getSelectedItem());
jungViewer = new Jung2DViewer(maps);
jPanelRight.add(jungViewer.getRenderer(), BorderLayout.CENTER);
}
/**
* This method initializes jPanelCenter
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelRight() {
if (jPanelRight == null) {
BorderLayout borderLayout = new BorderLayout();
HeadRight = new JLabel();
HeadRight.setFont(new Font("Dialog", Font.BOLD, 18));
HeadRight.setVerticalAlignment(SwingConstants.TOP);
HeadRight.setHorizontalAlignment(SwingConstants.CENTER);
HeadRight.setText("2D View");
jPanelRight = new JPanel();
jPanelRight.setLayout(borderLayout);
jPanelRight.add(HeadRight, BorderLayout.NORTH);
}
return jPanelRight;
}
/**
* This method initializes jPanelLeft
*
* @return javax.swing.JPanel
*/
private JPanel getJPanelLeft() {
if (jPanelLeft == null) {
GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
gridBagConstraints41.fill = GridBagConstraints.VERTICAL;
gridBagConstraints41.gridy = 2;
gridBagConstraints41.weightx = 1.0;
gridBagConstraints41.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints41.gridx = 1;
GridBagConstraints gridBagConstraints33 = new GridBagConstraints();
gridBagConstraints33.fill = GridBagConstraints.VERTICAL;
gridBagConstraints33.gridy = 13;
gridBagConstraints33.weightx = 1.0;
gridBagConstraints33.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints33.insets = new Insets(0, 0, 7, 0);
gridBagConstraints33.gridx = 1;
GridBagConstraints gridBagConstraints23 = new GridBagConstraints();
gridBagConstraints23.gridx = 0;
gridBagConstraints23.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints23.gridy = 13;
SelectConcepts = new JLabel();
SelectConcepts.setHorizontalAlignment(SwingConstants.LEFT);
SelectConcepts.setText("Select Concept:");
SelectConcepts.setVerticalAlignment(SwingConstants.TOP);
SelectConcepts.setHorizontalTextPosition(SwingConstants.CENTER);
GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
gridBagConstraints16.gridx = 0;
gridBagConstraints16.anchor = GridBagConstraints.WEST;
gridBagConstraints16.insets = new Insets(18, 0, 10, 0);
gridBagConstraints16.gridy = 12;
Relations1 = new JLabel();
Relations1.setHorizontalAlignment(SwingConstants.LEFT);
Relations1.setText("Causal Relations");
Relations1.setVerticalAlignment(SwingConstants.TOP);
Relations1.setHorizontalTextPosition(SwingConstants.CENTER);
GridBagConstraints gridBagConstraints32 = new GridBagConstraints();
gridBagConstraints32.gridx = 0;
gridBagConstraints32.anchor = GridBagConstraints.NORTHEAST;
gridBagConstraints32.insets = new Insets(0, 0, 0, 9);
gridBagConstraints32.gridy = 9;
Text1 = new JLabel();
Text1.setText("To:");
GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
gridBagConstraints22.gridx = 0;
gridBagConstraints22.anchor = GridBagConstraints.NORTHEAST;
gridBagConstraints22.insets = new Insets(0, 0, 0, 9);
gridBagConstraints22.gridy = 8;
Text = new JLabel();
Text.setText("From:");
GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
gridBagConstraints15.fill = GridBagConstraints.VERTICAL;
gridBagConstraints15.gridy = 9;
gridBagConstraints15.weightx = 1.0;
gridBagConstraints15.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints15.insets = new Insets(0, 0, 10, 0);
gridBagConstraints15.gridx = 1;
GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
gridBagConstraints14.gridx = 0;
gridBagConstraints14.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints14.gridy = 15;
OutLinks = new JLabel();
OutLinks.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
OutLinks.setHorizontalTextPosition(SwingConstants.CENTER);
OutLinks.setText("Outgoing Links:");
OutLinks.setVerticalAlignment(SwingConstants.TOP);
OutLinks.setVerticalTextPosition(SwingConstants.TOP);
OutLinks.setHorizontalAlignment(SwingConstants.LEADING);
GridBagConstraints gridBagConstraints13 = new GridBagConstraints();
gridBagConstraints13.fill = GridBagConstraints.BOTH;
gridBagConstraints13.gridy = 15;
gridBagConstraints13.weightx = 1.0;
gridBagConstraints13.weighty = 1.0;
gridBagConstraints13.anchor = GridBagConstraints.WEST;
gridBagConstraints13.gridx = 1;
GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
gridBagConstraints12.fill = GridBagConstraints.BOTH;
gridBagConstraints12.gridy = 14;
gridBagConstraints12.weightx = 1.0;
gridBagConstraints12.weighty = 1.0;
gridBagConstraints12.anchor = GridBagConstraints.WEST;
gridBagConstraints12.insets = new Insets(0, 0, 9, 0);
gridBagConstraints12.gridx = 1;
GridBagConstraints gridBagConstraints111 = new GridBagConstraints();
gridBagConstraints111.gridx = 0;
gridBagConstraints111.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints111.gridy = 14;
InLinks = new JLabel();
InLinks.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
InLinks.setHorizontalTextPosition(SwingConstants.CENTER);
InLinks.setText("Incoming Links:");
InLinks.setVerticalAlignment(SwingConstants.TOP);
InLinks.setVerticalTextPosition(SwingConstants.TOP);
InLinks.setHorizontalAlignment(SwingConstants.LEADING);
GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
gridBagConstraints10.fill = GridBagConstraints.VERTICAL;
gridBagConstraints10.gridy = 10;
gridBagConstraints10.weightx = 1.0;
gridBagConstraints10.anchor = GridBagConstraints.WEST;
gridBagConstraints10.ipadx = 0;
gridBagConstraints10.gridwidth = 1;
gridBagConstraints10.insets = new Insets(3, 0, 3, 0);
gridBagConstraints10.gridx = 1;
GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
gridBagConstraints9.gridx = 0;
gridBagConstraints9.anchor = GridBagConstraints.WEST;
gridBagConstraints9.gridy = 10;
jLabelWeight = new JLabel();
jLabelWeight.setText("Weight");
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.gridx = 1;
gridBagConstraints7.anchor = GridBagConstraints.WEST;
gridBagConstraints7.gridy = 11;
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridx = 0;
gridBagConstraints6.anchor = GridBagConstraints.WEST;
gridBagConstraints6.gridy = 2;
mapListText = new JLabel();
mapListText.setText("List of maps");
GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
gridBagConstraints5.gridx = 0;
gridBagConstraints5.anchor = GridBagConstraints.WEST;
gridBagConstraints5.insets = new Insets(18, 0, 10, 0);
gridBagConstraints5.gridy = 1;
mapsText = new JLabel();
mapsText.setFont(new Font("Dialog", Font.BOLD, 12));
mapsText.setText("Maps");
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.fill = GridBagConstraints.VERTICAL;
gridBagConstraints4.gridy = 8;
gridBagConstraints4.weightx = 1.0;
gridBagConstraints4.anchor = GridBagConstraints.WEST;
gridBagConstraints4.insets = new Insets(0, 0, 9, 0);
gridBagConstraints4.gridx = 1;
GridBagConstraints gridBagConstraints31 = new GridBagConstraints();
gridBagConstraints31.gridx = 0;
gridBagConstraints31.anchor = GridBagConstraints.WEST;
gridBagConstraints31.gridy = 7;
InsertLink = new JLabel();
InsertLink.setText("Insert Causal Link:");
GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
gridBagConstraints21.gridx = 1;
gridBagConstraints21.anchor = GridBagConstraints.WEST;
gridBagConstraints21.gridy = 5;
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.gridx = 0;
gridBagConstraints11.anchor = GridBagConstraints.WEST;
gridBagConstraints11.insets = new Insets(18, 0, 14, 0);
gridBagConstraints11.gridy = 6;
Relations = new JLabel();
Relations.setHorizontalAlignment(SwingConstants.LEFT);
Relations.setText("Causal Relations");
Relations.setVerticalAlignment(SwingConstants.TOP);
Relations.setHorizontalTextPosition(SwingConstants.CENTER);
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.fill = GridBagConstraints.VERTICAL;
gridBagConstraints3.gridy = 4;
gridBagConstraints3.weightx = 0.0;
gridBagConstraints3.ipady = 0;
gridBagConstraints3.gridwidth = 7;
gridBagConstraints3.insets = new Insets(0, 0, 0, 0);
gridBagConstraints3.anchor = GridBagConstraints.WEST;
gridBagConstraints3.gridx = 1;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 0;
gridBagConstraints2.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints2.ipadx = 80;
gridBagConstraints2.anchor = GridBagConstraints.WEST;
gridBagConstraints2.insets = new Insets(0, 0, 0, 0);
gridBagConstraints2.gridy = 4;
Insert = new JLabel();
Insert.setText("Insert new concept:");
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.gridwidth = 1;
gridBagConstraints.anchor = GridBagConstraints.WEST;
gridBagConstraints.insets = new Insets(18, 0, 10, 0);
gridBagConstraints.gridy = 3;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 0.0;
gridBagConstraints1.fill = GridBagConstraints.NONE;
gridBagConstraints1.ipadx = 0;
gridBagConstraints1.anchor = GridBagConstraints.CENTER;
gridBagConstraints1.insets = new Insets(0, 0, 0, 0);
gridBagConstraints1.gridheight = 1;
gridBagConstraints1.gridwidth = 2;
gridBagConstraints1.gridy = 0;
Concepts = new JLabel();
Concepts.setHorizontalAlignment(SwingConstants.LEFT);
Concepts.setText("Concepts");
Concepts.setVerticalAlignment(SwingConstants.TOP);
Concepts.setHorizontalTextPosition(SwingConstants.CENTER);
Head = new JLabel();
Head.setFont(new Font("Dialog", Font.BOLD, 18));
Head.setVerticalAlignment(SwingConstants.TOP);
Head.setText("Map Features");
jPanelLeft = new JPanel();
jPanelLeft.setLayout(new GridBagLayout());
jPanelLeft.setFont(new Font("Dialog", Font.BOLD, 12));
jPanelLeft.add(Head, gridBagConstraints1);
jPanelLeft.add(Concepts, gridBagConstraints);
jPanelLeft.add(Insert, gridBagConstraints2);
jPanelLeft.add(getConceptText(), gridBagConstraints3);
jPanelLeft.add(Relations, gridBagConstraints11);
jPanelLeft.add(getSaveButton(), gridBagConstraints21);
jPanelLeft.add(InsertLink, gridBagConstraints31);
jPanelLeft.add(getJComboBoxCausalLinksFrom(), gridBagConstraints4);
jPanelLeft.add(mapsText, gridBagConstraints5);
jPanelLeft.add(mapListText, gridBagConstraints6);
jPanelLeft.add(getSaveButtonLink(), gridBagConstraints7);
jPanelLeft.add(jLabelWeight, gridBagConstraints9);
jPanelLeft.add(getJTextFieldWeight(), gridBagConstraints10);
jPanelLeft.add(InLinks, gridBagConstraints111);
jPanelLeft.add(getInTextLinks(), gridBagConstraints12);
jPanelLeft.add(getOutTextLinks(), gridBagConstraints13);
jPanelLeft.add(OutLinks, gridBagConstraints14);
jPanelLeft.add(getJComboBoxCausalLinksTo(), gridBagConstraints15);
jPanelLeft.add(Text, gridBagConstraints22);
jPanelLeft.add(Text1, gridBagConstraints32);
jPanelLeft.add(Relations1, gridBagConstraints16);
jPanelLeft.add(SelectConcepts, gridBagConstraints23);
jPanelLeft.add(getJComboBoxMapConcepts(), gridBagConstraints33);
jPanelLeft.add(getJComboBoxMapList(), gridBagConstraints41);
}
return jPanelLeft;
}
/**
* This method initializes conceptText
*
* @return javax.swing.JTextField
*/
private JTextField getConceptText() {
if (conceptText == null) {
conceptText = new JTextField();
conceptText.setPreferredSize(new Dimension(180, 20));
conceptText.setColumns(16);
}
return conceptText;
}
/**
* This method initializes SaveButton
*
* @return javax.swing.JButton
*/
private JButton getSaveButton() {
if (SaveButton == null) {
SaveButton = new JButton();
SaveButton.setFont(new Font("Dialog", Font.BOLD, 12));
SaveButton.setText("Insert Concept");
SaveButton.setPreferredSize(new Dimension(180, 20));
}
return SaveButton;
}
/**
* This method initializes jComboBoxCausalLinksFrom
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBoxCausalLinksFrom() {
if (jComboBoxCausalLinksFrom == null) {
jComboBoxCausalLinksFrom = new JComboBox();
jComboBoxCausalLinksFrom.setFont(new Font("Dialog", Font.BOLD, 12));
jComboBoxCausalLinksFrom.setPreferredSize(new Dimension(180, 20));
}
return jComboBoxCausalLinksFrom;
}
/**
* This method initializes jComboBoxMapList
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBoxMapList() {
if (jComboBoxMapList == null) {
jComboBoxMapList = new JComboBox();
jComboBoxMapList.setPreferredSize(new Dimension(180, 20));
jComboBoxMapList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String mapName = (String) jComboBoxMapList.getSelectedItem();
String[] mapConcepts = maps.get(mapName).getConcepts().keySet().toArray(new String[0]);
jComboBoxCausalLinksFrom.removeAllItems();
//jComboBoxCausalLinksFrom.addItem(null);
jComboBoxCausalLinksTo.removeAllItems();
//jComboBoxCausalLinksTo.addItem(null);
jComboBoxMapConcepts.removeAllItems();
for(String concept : mapConcepts){
jComboBoxCausalLinksFrom.addItem(concept);
jComboBoxCausalLinksTo.addItem(concept);
jComboBoxMapConcepts.addItem(concept);
}
}
});
}
return jComboBoxMapList;
}
/**
* This method initializes SaveButtonLink
*
* @return javax.swing.JButton
*/
private JButton getSaveButtonLink() {
if (SaveButtonLink == null) {
SaveButtonLink = new JButton();
SaveButtonLink.setFont(new Font("Dialog", Font.BOLD, 12));
SaveButtonLink.setText("Insert Link");
SaveButtonLink.setPreferredSize(new Dimension(180, 20));
}
return SaveButtonLink;
}
/**
* This method initializes jTextFieldWeight
*
* @return javax.swing.JTextField
*/
private JTextField getJTextFieldWeight() {
if (jTextFieldWeight == null) {
jTextFieldWeight = new JTextField();
jTextFieldWeight.setColumns(4);
}
return jTextFieldWeight;
}
/**
* This method initializes InTextLinks
*
* @return javax.swing.JTextPane
*/
private JTextPane getInTextLinks() {
if (InTextLinks == null) {
InTextLinks = new JTextPane();
InTextLinks.setBackground(SystemColor.control);
InTextLinks.setText("Incoming Links");
InTextLinks.setPreferredSize(new Dimension(6, 10));
}
return InTextLinks;
}
/**
* This method initializes OutTextLinks
*
* @return javax.swing.JTextPane
*/
private JTextPane getOutTextLinks() {
if (OutTextLinks == null) {
OutTextLinks = new JTextPane();
OutTextLinks.setBackground(SystemColor.control);
OutTextLinks.setText("Outgoing Links");
OutTextLinks.setPreferredSize(new Dimension(6, 10));
}
return OutTextLinks;
}
/**
* This method initializes jComboBoxCausalLinksTo
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBoxCausalLinksTo() {
if (jComboBoxCausalLinksTo == null) {
jComboBoxCausalLinksTo = new JComboBox();
jComboBoxCausalLinksTo.setFont(new Font("Dialog", Font.BOLD, 12));
jComboBoxCausalLinksTo.setPreferredSize(new Dimension(180, 20));
}
return jComboBoxCausalLinksTo;
}
/**
* This method initializes jComboBoxMapConcepts
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBoxMapConcepts() {
if (jComboBoxMapConcepts == null) {
jComboBoxMapConcepts = new JComboBox();
jComboBoxMapConcepts.setFont(new Font("Dialog", Font.BOLD, 12));
jComboBoxMapConcepts.setPreferredSize(new Dimension(180, 20));
jComboBoxMapConcepts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
/* Update the jTextFields */
String incoming = new String(), outgoing = new String();
// Get selected map
String map = (String) jComboBoxMapList.getSelectedItem();
// Get the selected item
String concept = (String) jComboBoxMapConcepts.getSelectedItem();
if(map == null || concept == null){
InTextLinks.setText("");
OutTextLinks.setText("");
return;
}
// Get Fcm Connections
Collection<FcmConnection> links = maps.get(map).getConnections().values();
Iterator<FcmConnection> it = links.iterator();
while(it.hasNext()){
FcmConnection c = it.next();
String source = c.getFrom().getName();
String destination = c.getTo().getName();
if(concept.equals(source))
outgoing+=destination + "\n";
if(concept.equals(destination))
incoming+=source + "\n";
//Set the new texts
InTextLinks.setText(incoming);
OutTextLinks.setText(outgoing);
}
}
});
}
return jComboBoxMapConcepts;
}
/**
* Launches this application
*/
public static void main(String[] args) {
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e1)
{
e1.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MapEditor application = new MapEditor();
application.getJFrame().setVisible(true);
}
});
}
}