| 1 |  |  package de.glossmaker.gui.gloss.main; | 
  | 2 |  |   | 
  | 3 |  |  import guihelper.statusbar.StatusBar; | 
  | 4 |  |   | 
  | 5 |  |  import java.awt.BorderLayout; | 
  | 6 |  |  import java.awt.Dimension; | 
  | 7 |  |  import java.awt.EventQueue; | 
  | 8 |  |  import java.beans.PropertyChangeEvent; | 
  | 9 |  |  import java.beans.PropertyChangeListener; | 
  | 10 |  |   | 
  | 11 |  |  import javax.swing.JLabel; | 
  | 12 |  |  import javax.swing.JOptionPane; | 
  | 13 |  |  import javax.swing.JPanel; | 
  | 14 |  |  import javax.swing.JSplitPane; | 
  | 15 |  |   | 
  | 16 |  |  import de.glossmaker.gloss.datastructure.GlossItems; | 
  | 17 |  |  import de.glossmaker.gloss.datastructure.gui.Config; | 
  | 18 |  |  import de.glossmaker.gloss.language.Translation; | 
  | 19 |  |  import de.glossmaker.gloss.listener.EActionCommands; | 
  | 20 |  |  import de.glossmaker.gloss.observer.GlossItemsChangePublisher; | 
  | 21 |  |  import de.glossmaker.gui.gloss.bars.ToolBar; | 
  | 22 |  |  import de.glossmaker.gui.gloss.main.definition.DefinitionPanel; | 
  | 23 |  |  import de.glossmaker.gui.gloss.main.tableview.GlossItemTablePanel; | 
  | 24 |  |  import de.glossmaker.gui.gloss.main.tree.NavigationTreePanel; | 
  | 25 |  |   | 
  | 26 |  |   | 
  | 27 |  |   | 
  | 28 |  |   | 
  | 29 |  |   | 
  | 30 |  |   | 
  | 31 |  |  public class MainInputPanel extends JPanel implements PropertyChangeListener { | 
  | 32 |  |          private static final long serialVersionUID = 4689650016500222321L; | 
  | 33 | 0 |          private static boolean isTreeVisible = true; | 
  | 34 | 0 |          private JSplitPane mSplitPane = null; | 
  | 35 | 0 |          private NavigationTreePanel mTreePanel = null; | 
  | 36 | 0 |          private JPanel mMainPanel = null; | 
  | 37 | 0 |          private JPanel mTablePanel = null; | 
  | 38 | 0 |          private GlossItems mGlossItems = null; | 
  | 39 |  |          private ToolBar mToolbar; | 
  | 40 |  |           | 
  | 41 | 0 |          public MainInputPanel(GlossItems items) { | 
  | 42 | 0 |                  mGlossItems = items; | 
  | 43 | 0 |                  GlossItemsChangePublisher.getInstance(items).addPropertyChangeListener(this); | 
  | 44 | 0 |                  initialize(); | 
  | 45 | 0 |          } | 
  | 46 |  |           | 
  | 47 |  |          private void initialize() { | 
  | 48 | 0 |                  this.setLayout(new BorderLayout()); | 
  | 49 | 0 |                  this.setPreferredSize(new Dimension(400, 400)); | 
  | 50 | 0 |                  this.setSize(new Dimension(40, 400)); | 
  | 51 | 0 |                  this.setPreferredSize(new Dimension(400, 400)); | 
  | 52 | 0 |                  mToolbar = new ToolBar(mGlossItems); | 
  | 53 | 0 |                  this.add(mToolbar, BorderLayout.NORTH); | 
  | 54 | 0 |                  this.add(getSplitPane(), BorderLayout.CENTER); | 
  | 55 | 0 |                  JPanel panel = new JPanel(new BorderLayout()); | 
  | 56 | 0 |                  JLabel label = new JLabel("  "); | 
  | 57 | 0 |                  label.setSize(new Dimension(10, 20)); | 
  | 58 | 0 |                  panel.add(label, BorderLayout.WEST); | 
  | 59 | 0 |                  panel.add(new StatusBar(), BorderLayout.CENTER); | 
  | 60 | 0 |                  this.add(panel, BorderLayout.SOUTH); | 
  | 61 | 0 |          } | 
  | 62 |  |   | 
  | 63 |  |          private NavigationTreePanel getTreePanel() { | 
  | 64 | 0 |                  if (mTreePanel == null) { | 
  | 65 | 0 |                          mTreePanel = new NavigationTreePanel(mGlossItems); | 
  | 66 |  |                  } | 
  | 67 |  |                   | 
  | 68 | 0 |                  return mTreePanel; | 
  | 69 |  |          } | 
  | 70 |  |   | 
  | 71 |  |           | 
  | 72 |  |          private JPanel getMainPanel() { | 
  | 73 | 0 |                  if (mMainPanel == null) { | 
  | 74 | 0 |                          mMainPanel = new JPanel(new BorderLayout()); | 
  | 75 | 0 |                          mMainPanel.add(new TopPanel(mGlossItems), BorderLayout.NORTH); | 
  | 76 | 0 |                          mMainPanel.add(new DefinitionPanel(mGlossItems), BorderLayout.CENTER);                         | 
  | 77 |  |                  } | 
  | 78 |  |                   | 
  | 79 | 0 |                  return mMainPanel; | 
  | 80 |  |          } | 
  | 81 |  |   | 
  | 82 |  |          private JPanel getTablePanel() { | 
  | 83 | 0 |                  if (mTablePanel == null) { | 
  | 84 | 0 |                          mTablePanel = new GlossItemTablePanel(mGlossItems); | 
  | 85 |  |                  } | 
  | 86 |  |                   | 
  | 87 | 0 |                  return mTablePanel; | 
  | 88 |  |          } | 
  | 89 |  |           | 
  | 90 |  |          private JSplitPane getSplitPane() { | 
  | 91 | 0 |                  if (mSplitPane == null) { | 
  | 92 | 0 |                          mSplitPane = new JSplitPane(); | 
  | 93 | 0 |                          mSplitPane.setPreferredSize(new Dimension(600, 400)); | 
  | 94 | 0 |                          mSplitPane.setSize(new Dimension(600, 400)); | 
  | 95 | 0 |                          mSplitPane.setLeftComponent(getTreePanel()); | 
  | 96 | 0 |                          mSplitPane.setDividerLocation(200); | 
  | 97 | 0 |                          mSplitPane.setRightComponent(getMainPanel()); | 
  | 98 | 0 |                          mSplitPane.setOneTouchExpandable(true);                                         | 
  | 99 |  |                           | 
  | 100 |  |                  } | 
  | 101 | 0 |                  return mSplitPane; | 
  | 102 |  |          } | 
  | 103 |  |   | 
  | 104 |  |          @Override | 
  | 105 |  |          public void propertyChange(PropertyChangeEvent event) { | 
  | 106 | 0 |                  if (event.getPropertyName().equals(EActionCommands.SHOW_TABLE_VIEW.toString())) {                         | 
  | 107 | 0 |                          if (isTreeVisible) { | 
  | 108 | 0 |                                  this.remove(getSplitPane()); | 
  | 109 | 0 |                                  this.add(getTablePanel(), BorderLayout.CENTER); | 
  | 110 |  |                          } else { | 
  | 111 | 0 |                                  this.remove(getTablePanel()); | 
  | 112 | 0 |                                  this.add(getSplitPane(), BorderLayout.CENTER); | 
  | 113 |  |                                   | 
  | 114 |  |                          } | 
  | 115 | 0 |                          isTreeVisible = !isTreeVisible; | 
  | 116 | 0 |                          EventQueue.invokeLater(new Runnable() { | 
  | 117 |  |   | 
  | 118 |  |                                  public void run() { | 
  | 119 | 0 |                                          MainInputPanel.this.updateUI(); | 
  | 120 | 0 |                                  } | 
  | 121 |  |                          }); | 
  | 122 | 0 |                  } else if (event.getPropertyName().equals(EActionCommands.FILE_NOT_OPENED.toString())) { | 
  | 123 | 0 |                          String errorMsg = Translation.getInstance().getValue("statusbar.info.file_not_opened.text", (String)event.getNewValue()); | 
  | 124 | 0 |                          JOptionPane.showConfirmDialog(null, | 
  | 125 |  |                                          errorMsg, | 
  | 126 |  |                                          Translation.getInstance().getValue("error.file_not_opened.title"), | 
  | 127 |  |                                          JOptionPane.WARNING_MESSAGE); | 
  | 128 | 0 |                  } else if (event.getPropertyName().equals(EActionCommands.OPEN_FILE.toString())) { | 
  | 129 | 0 |                          Config.getInstance().addLastOpenedFile((String) event.getNewValue()); | 
  | 130 |  |                  } | 
  | 131 |  |                   | 
  | 132 | 0 |          } | 
  | 133 |  |   | 
  | 134 |  |           | 
  | 135 |  |  } |