home *** CD-ROM | disk | FTP | other *** search
Wrap
package com.extensibility.xa; import com.extensibility.app.BaseAction; import com.extensibility.app.BaseDocument; import com.extensibility.app.BaseUndoable; import com.extensibility.app.DialogFactory; import com.extensibility.app.UI; import com.extensibility.rock.RButton; import com.extensibility.rock.SimpleListPopup; import com.extensibility.xml.ExternalSubset; import com.extensibility.xml.ParserException; import com.extensibility.xml.URI; import java.awt.Cursor; import java.awt.Font; import java.awt.Insets; import java.awt.event.ActionEvent; import java.util.Enumeration; import java.util.Vector; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.event.UndoableEditListener; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultEditorKit; import javax.swing.undo.UndoManager; public abstract class BaseSourcePane extends CompositePane { JTextArea sourceText = new 1((BaseSourcePane)null); JScrollPane sourceScroll; JButton modulePicker; boolean dirty = false; boolean inSync = false; boolean inReparse = false; boolean ignoreMyCommitPending = false; boolean inRefresh = false; URI uri; UndoableEditListener undoListener; SourceUndoManager undoManager = new SourceUndoManager((BaseSourcePane)null); SchemaDocListener docListener = new 5(this); BaseAction refreshAction = null; BaseAction parseAction = null; public BaseSourcePane(SchemaDoc var1) { super(var1); Font var2 = UI.getSrcFont(); if (var2 != null) { this.sourceText.setFont(var2); } this.sourceText.setMargin(new Insets(4, 4, 4, 4)); this.sourceScroll = new JScrollPane(this.sourceText); this.sourceText.setCursor(Cursor.getPredefinedCursor(2)); this.sourceText.getDocument().addDocumentListener(new 2(this)); ((CompositePane)this).getSchemaDoc().addDocumentListener(this.docListener); this.undoListener = new MyUndoableEditListener(this); this.sourceText.getDocument().addUndoableEditListener(this.undoListener); this.modulePicker = new JButton(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(((CompositePane)this).getSchemaDoc().getURI().getFullName()))); this.modulePicker.addMouseListener(new 3(this)); this.uri = ((BaseDocument)var1).getURI(); CompositePane.setHeader(this.sourceScroll, this.modulePicker, new RButton(this.createParseAction())); } public void showError(ParserException var1) { int var2 = var1.getSourceLinePos() - 1; try { int var3 = this.sourceText.getLineStartOffset(var2); int var4 = this.sourceText.getLineEndOffset(var2); this.sourceText.select(var3, var4); } catch (BadLocationException var5) { } } protected void addSetURIAction(Vector var1, ExternalSubset var2) { URI var3 = var2.getSystemURI(); boolean var4 = this.uri.equals(var3); String var5 = var3.getShortName(); if (var5.length() == 0) { var5 = UI.getString("untitled.window"); } if (var4) { var5 = String.valueOf("* ").concat(String.valueOf(var5)); } SimpleListPopup.ListEntry var6 = new SimpleListPopup.ListEntry(var5, new 4(var3, this)); var1.addElement(var6); Enumeration var7 = var2.children(); while(var7.hasMoreElements()) { this.addSetURIAction(var1, (ExternalSubset)var7.nextElement()); } } public void uriUpdateNotify(URI var1, URI var2) { if (this.uri.equals(var1)) { this.uri = var2; this.modulePicker.setText(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(this.uri.getFullName()))); } } public JComponent getComponent() { return this.sourceScroll; } public boolean setURI(URI var1) { if (!this.commitPendingEdits(true)) { return false; } else { this.uri = var1; this.modulePicker.setText(String.valueOf(this.getHeaderPrefix()).concat(String.valueOf(var1.getFullName()))); this.inSync = false; if (this.isAdded()) { this.refresh(); } return true; } } public void discard() { this.inSync = false; this.dirty = false; } public boolean commitPendingEdits(boolean var1) { if (this.ignoreMyCommitPending) { return true; } else { if (this.dirty) { int var2 = XADialogFactory.askParseChanges(this.getComponent()); if (var2 == 0) { return false; } if (var2 == 1) { this.discard(); } else { this.parseAction.actionOccurred((ActionEvent)null); } } return true; } } public boolean isAdded() { return this.getComponent().getParent() != null; } public boolean addRequest() { return true; } protected void setDirty(boolean var1) { this.dirty = var1; if (!this.dirty) { this.inSync = true; } } protected boolean isDirty() { return this.dirty; } protected boolean isInSync() { return this.inSync; } protected void setInSync(boolean var1) { this.inSync = var1; } protected boolean hasDeclTable() { return false; } public String getClassName() { return "com.extensibility.xa.BaseSourcePane"; } protected void checkJDKBug() { if (this.sourceText.getLineCount() > 1024) { DialogFactory.caution(this.getComponent(), UI.getString("bug.jdk.textarea.size")); } } protected abstract void refresh(); protected abstract String getHeaderPrefix(); protected abstract BaseUndoable createSourceRefreshUndoable(); protected abstract BaseUndoable createSourceReparseUndoable(); protected void dataChanged() { if (!this.inReparse) { this.inSync = false; if (this.isAdded() && !this.isDirty()) { this.refresh(); } } } public JTextArea getSourceText() { return this.sourceText; } protected abstract BaseAction createRefreshAction(); protected abstract BaseAction createParseAction(); protected BaseAction createUndoAction() { return this.undoManager.getUndoAction(); } protected BaseAction createRedoAction() { return this.undoManager.getRedoAction(); } public void cut() { (new DefaultEditorKit.CutAction()).actionPerformed((ActionEvent)null); } public void copy() { (new DefaultEditorKit.CopyAction()).actionPerformed((ActionEvent)null); } public void paste() { (new DefaultEditorKit.PasteAction()).actionPerformed((ActionEvent)null); } public void clear() { this.sourceText.replaceSelection(""); } public boolean find(String var1, boolean var2) { String var3 = this.sourceText.getText(); int var4 = var3.indexOf(var1, var2 ? 0 : this.sourceText.getSelectionStart() + 1); if (var4 >= 0) { this.sourceText.select(var4, var4 + var1.length()); return true; } else { return var2 ? false : this.find(var1, true); } } public String getSelectedText() { return this.sourceText.getSelectedText(); } public boolean setSelectedText(String var1) { if (!this.sourceText.isEditable()) { return false; } else { this.sourceText.replaceSelection(var1); return true; } } public UndoManager getUndoManager() { return this.undoManager; } }