1 package org.antlr.works.components; 2 3 import org.antlr.xjlib.appkit.document.XJDocument; 4 import org.antlr.xjlib.appkit.frame.XJFrameInterface; 5 import org.antlr.xjlib.appkit.menu.XJMainMenuBar; 6 import org.antlr.xjlib.appkit.menu.XJMenu; 7 import org.antlr.xjlib.appkit.menu.XJMenuItem; 8 import org.antlr.xjlib.appkit.undo.XJUndo; 9 import org.antlr.xjlib.foundation.notification.XJNotificationCenter; 10 import org.antlr.xjlib.foundation.notification.XJNotificationObserver; 11 import org.antlr.works.debugger.Debugger; 12 import org.antlr.works.prefs.AWPrefsDialog; 13 14 import javax.swing.*; 15 import java.awt.*; 16 import java.awt.event.ComponentAdapter ; 17 import java.awt.event.ComponentEvent ; 18 import java.beans.PropertyChangeEvent ; 19 import java.beans.PropertyChangeListener ; 20 import java.util.Map ; 21 22 52 53 public abstract class ComponentEditor implements XJNotificationObserver { 54 55 protected ComponentContainer container; 56 protected JPanel mainPanel; 57 protected Box statusBar; 58 59 public ComponentEditor(ComponentContainer container) { 60 this.container = container; 61 62 mainPanel = new JPanel(new BorderLayout()); 63 mainPanel.addComponentListener(new MainPanelComponentListener()); 64 65 statusBar = new ComponentStatusBar(); 66 statusBar.setPreferredSize(new Dimension(0, 30)); 67 68 XJNotificationCenter.defaultCenter().addObserver(this, AWPrefsDialog.NOTIF_PREFS_APPLIED); 69 XJNotificationCenter.defaultCenter().addObserver(this, Debugger.NOTIF_DEBUG_STARTED); 70 XJNotificationCenter.defaultCenter().addObserver(this, Debugger.NOTIF_DEBUG_STOPPED); 71 72 KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); 73 focusManager.addPropertyChangeListener( 74 new PropertyChangeListener () { 75 public void propertyChange(PropertyChangeEvent e) { 76 String prop = e.getPropertyName(); 77 if(prop.equals("permanentFocusOwner")) 78 XJMainMenuBar.refreshAllMenuBars(); 79 } 80 } 81 ); 82 83 } 84 85 public void refreshMainMenuBar() { 86 if(getXJFrame().getMainMenuBar() != null) 87 getXJFrame().getMainMenuBar().refreshState(); 88 } 89 90 public JComponent getToolbarComponent() { 91 return null; 92 } 93 94 public JComponent getStatusComponent() { 95 return statusBar; 96 } 97 98 public XJDocument getDocument() { 99 return container.getDocument(); 100 } 101 102 public XJFrameInterface getXJFrame() { 103 return container.getXJFrame(); 104 } 105 106 public Container getJavaContainer() { 107 return getXJFrame().getJavaContainer(); 108 } 109 110 public JPanel getPanel() { 111 return mainPanel; 112 } 113 114 public XJUndo getCurrentUndo() { 115 return getXJFrame().getCurrentUndo(); 116 } 117 118 public void notificationFire(Object source, String name) { 119 if(name.equals(AWPrefsDialog.NOTIF_PREFS_APPLIED)) { 120 notificationPrefsChanged(); 121 } else if(name.equals(Debugger.NOTIF_DEBUG_STARTED)) { 122 notificationDebuggerStarted(); 123 } else if(name.equals(Debugger.NOTIF_DEBUG_STOPPED)) { 124 notificationDebuggerStopped(); 125 } 126 } 127 128 protected static JComponent createSeparator() { 129 JSeparator s = new JSeparator(SwingConstants.VERTICAL); 130 Dimension d = s.getMaximumSize(); 131 d.width = 2; 132 s.setMaximumSize(d); 133 return s; 134 } 135 136 139 140 public abstract void create(); 141 public abstract void assemble(); 142 143 public abstract void loadText(String text); 144 145 public abstract String getText(); 146 147 public void close() { 148 XJNotificationCenter.defaultCenter().removeObserver(this); 149 } 150 151 public abstract void componentDocumentContentChanged(); 152 153 public boolean componentDocumentWillSave() { 154 return true; 155 } 156 157 public void setPersistentData(Map data) { 158 159 } 160 161 public Map <String , Object > getPersistentData() { 162 return null; 163 } 164 165 public void componentShouldLayout(Dimension size) { 166 167 } 168 169 public void componentDidAwake() { 170 } 171 172 public void customizeFileMenu(XJMenu menu) { 173 } 174 175 public void customizeEditMenu(XJMenu menu) { 176 } 177 178 public void customizeWindowMenu(XJMenu menu) { 179 } 180 181 public void customizeHelpMenu(XJMenu menu) { 182 } 183 184 public void customizeMenuBar(XJMainMenuBar menubar) { 185 } 186 187 public void menuItemState(XJMenuItem item) { 188 } 189 190 public void handleMenuSelected(XJMenu menu) { 191 } 192 193 public void componentActivated() { 194 } 195 196 public void componentDidHide() { 197 198 } 199 200 public void componentIsSelected() { 201 } 202 203 public void notificationPrefsChanged() { 204 } 205 206 public void notificationDebuggerStarted() { 207 } 208 209 public void notificationDebuggerStopped() { 210 } 211 212 protected class MainPanelComponentListener extends ComponentAdapter { 213 public void componentHidden(ComponentEvent e) { 214 componentDidHide(); 215 } 216 } 217 218 } 219 | Popular Tags |