Undo problem in DefaultStyledDocument!
Just run this code, and you won't be able to type in the editor pane! What's the problem? Indeed the problem arose from the setCharacterAttributes(), and rejection of change events in the overriden implementation of undoableEditHappened from UndoManager. How can this be fixed? Please don't say I'm supposed to save all these change events and undo them as well.
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.undo.UndoManager;
public class pad {
public static void main(String[] arguments) throws BadLocationException {
JFrame pad = new JFrame();
pad.setBounds(50, 50, 400, 300);
pad.setVisible(true);
JEditorPane editor = new JEditorPane();
pad.getContentPane().add(editor);
editor.setEditorKit(new StyledEditorKit());
DefaultStyledDocument document = (DefaultStyledDocument) editor.getDocument();
UndoManager undoManager = new UndoManager() {
public void undoableEditHappened(UndoableEditEvent e) {
// The problem arose from the rejection of change event here!
if (((DocumentEvent) e.getEdit()).getType() == DocumentEvent.EventType.CHANGE)
return;
super.undoableEditHappened(e);
document.addUndoableEditListener(undoManager);
editor.replaceSelection("n\n");
document.setCharacterAttributes(0, 1, SimpleAttributeSet.EMPTY, false);
undoManager.undo();
}
Of course if you replace "n\n" with "1" or any string not ending with '\n', it works fine! The "n\n" is a typical input which causes the malfunctioning of the UndoManager, and which the user may type! All I do is highlighting the input. Then the user tries to undo the last typed entries 'n', & '\n'! I've rejected the highlighting change events so that I can undo the user's input at each undo.
That's it! I didn't do anything wrong except not considering the change events!
Anyway, thanks for your attention camickr!
Regards,
--Rasta
Similar Messages
-
Text Layout Framework columncount Undo problem
Text Layout Framework columncount Undo problem ::
The number of times columncount is changed it gets applied to textflow
and those number of operation is stored in undoStack(UndoManger).But when i
undo it, it comes back to intial state, without undoin step by step.
I have given my source code..
Y so or any other alternative to achieve this..
Thanx in advance..
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init()">
<fx:Script>
<![CDATA[
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.conversion.ITextImporter;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import flashx.textLayout.edit.IEditManager;
import flashx.textLayout.edit.ISelectionManager;
import flashx.textLayout.edit.SelectionState;
import flashx.textLayout.elements.InlineGraphicElement;
import flashx.textLayout.elements.ParagraphElement;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.events.SelectionEvent;
import flashx.textLayout.events.StatusChangeEvent;
import flashx.textLayout.formats.Direction;
import flashx.textLayout.formats.TextLayoutFormat;
import flashx.undo.UndoManager;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.CheckBox;
import mx.events.FlexEvent;
import mx.events.SliderEvent;
import spark.components.Group;
import spark.components.TextArea;
import spark.core.SpriteVisualElement;
public var directions:ArrayCollection = new
ArrayCollection(
{label:"Left-to-Right",
data:Direction.LTR},
{label:"Right-to-Left",
data:Direction.RTL}
private var _textContainer:SpriteVisualElement = null;
private static const textInput:XML = <TextFlow
xmlns="http://ns.adobe.com/textLayout/2008">
<div>
<p><span>The Text Layout Framework is
an extensible library, built on the new text engine in Adobe Flash Player 10,
which delivers advanced, easy-to-integrate typographic and text layout features
for rich, sophisticated and innovative typography on the web.
Some benefits provided by this framework
include: 1) rich typographical controls, including kerning, ligatures,
typographic case, digit case, digit width and discretionary hyphens
2) cut, copy, paste, undo and standard keyboard
and mouse gestures for editing 3) selection, editing and flowing text across
multiple columns and linked containers
4) bidirectional text, vertical text and over
30 writing scripts including Arabic, Hebrew, Chinese, Japanese, Korean, Thai,
Lao, Vietnamese, and others
5) vertical text, Tate-Chu-Yoko (horizontal
within vertical text) and justifier for East Asian typography. Try editing this
text and playing with the options below! Notice an inline image is also
included.</span></p>
</div>
</TextFlow>;
private var _textFlow:TextFlow;
private function init():void {
_textContainer = new SpriteVisualElement();
canvas.addElement(_textContainer);
var importer:ITextImporter =
TextConverter.getImporter(TextConverter.TEXT_LAYOUT_FORMAT);
_textFlow = importer.importToFlow(textInput);
_textFlow.flowComposer.addController(new
ContainerController(_textContainer, canvas.width-40, canvas.height));
_textFlow.interactionManager = new
EditManager(new UndoManager());
_textFlow.flowComposer.updateAllControllers();
private function changeNoColumns(event:Event):void {
var tlf:TextLayoutFormat = new
TextLayoutFormat();
tlf.columnCount = cols.value;
tlf.columnGap = 15;
tlf.direction = direction.selectedItem.data;
var em:EditManager =
_textFlow.interactionManager as EditManager;
em.selectAll();
(_textFlow.interactionManager as
EditManager).applyFormat(tlf,tlf,tlf);
_textFlow.flowComposer.updateAllControllers();
protected function
undo_clickHandler(event:MouseEvent):void
var em:EditManager =
_textFlow.interactionManager as EditManager;
trace("Can undo " + em.undoManager.canUndo() +
" can redo " + em.undoManager.canRedo());
em.undo();
protected function
redo_clickHandler(event:MouseEvent):void
var em:EditManager =
_textFlow.interactionManager as EditManager;
trace("Can undo " + em.undoManager.canUndo() +
" can redo " + em.undoManager.canRedo());
em.redo();
]]>
</fx:Script>
<s:Panel title="Text Layout Framework Sample" width="100%"
height="100%">
<s:layout>
<s:VerticalLayout paddingTop="8" paddingLeft="8"/>
</s:layout>
<s:VGroup>
<s:Group id="canvas" width="600" height="200" />
<s:HGroup width="100%" verticalAlign="middle">
<s:Label text="# Columns:"/>
<s:NumericStepper id="cols" minimum="1"
maximum="20" snapInterval="1" change="changeNoColumns(event)" />
<s:Label text="Text Direction:"/>
<s:DropDownList id="direction"
change="changeTextDirection(event)" dataProvider="{directions}"
selectedItem="{directions[0]}"/>
<s:Button label="Undo"
click="undo_clickHandler(event)"/>
<s:Button label="Redo"
click="redo_clickHandler(event)"/>
</s:HGroup>
</s:VGroup>
</s:Panel>
</s:WindowedApplication>It cannot be reproduced with TLF 3.0 + SDK 4.5.
-
Hi, I'm using LR 2.2 and recently I've found that when I attempt to "Undo" something (Undo creative preset, Undo adjustment brush, Undo Grad filter) in Develop I get kicked out of the photo I'm working on, kicked out of the photo download group I'm working in and out into, the last time anyway, the first photo of the last group of photos I D/Led.
Has anyone else seen this? My LR is pretty standard with the exception of having added the TTG XML Auto Index 1.51 engine to the Web module. Any suggestions?Same here, got the same problem. Still don't know what caused it. Sometimes undo works as it should, sometimes it just throws me out of developer module into library grid mode. Strange..
-
I use StyledDocument in my program (text editor) and I have following exception:
javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Length must be positive
at javax.swing.text.GlyphView.getText(GlyphView.java:106)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:43)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:498)
at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:679)
at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:214)
at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:881)
at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
at javax.swing.text.BoxView.layout(BoxView.java:682)
at javax.swing.text.BoxView.setSize(BoxView.java:379)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1599)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:935)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:911)
at javax.swing.text.JTextComponent.modelToView(JTextComponent.java:1118)
at Editor.Editor.caretUpdate(Editor.java:1204)
at Editor.Editor.caretUpdate(Editor.java:686)
at javax.swing.text.JTextComponent.fireCaretUpdate(JTextComponent.java:356)
at javax.swing.text.JTextComponent$MutableCaretEvent.fire(JTextComponent.java:3165)
at javax.swing.text.JTextComponent$MutableCaretEvent.stateChanged(JTextComponent.java:3187)
at javax.swing.text.DefaultCaret.fireStateChanged(DefaultCaret.java:638)
at javax.swing.text.DefaultCaret.changeCaretPosition(DefaultCaret.java:1010)
at javax.swing.text.DefaultCaret.handleSetDot(DefaultCaret.java:918)
at javax.swing.text.DefaultCaret.setDot(DefaultCaret.java:899)
at javax.swing.text.DefaultCaret$UpdateHandler.insertUpdate(DefaultCaret.java:1453)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:184)
at Editor.OverwritableSyntaxDocument.fireInsertUpdate(OverwritableSyntaxDocument.java:52)
at javax.swing.text.AbstractDocument$DefaultDocumentEvent.undo(AbstractDocument.java:2797)
at javax.swing.undo.UndoManager.undoTo(UndoManager.java:210)
at javax.swing.undo.UndoManager.undo(UndoManager.java:275)
at Editor.Editor.actionPerformed(Editor.java:333)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
That exception occurs only if I try to undo some editons in first line of StyledDocument
In other lines it works without any problems.
I use following implementation:
public void undoableEditHappened(UndoableEditEvent e)
UndoableEdit edit=e.getEdit();
if(compoundEdit==null)
compoundEdit=new CompoundEdit();
if(edit instanceof AbstractDocument.DefaultDocumentEvent &&
((AbstractDocument.DefaultDocumentEvent)edit).getType()== AbstractDocument.DefaultDocumentEvent.EventType.CHANGE)
compoundEdit.addEdit(edit);
else
compoundEdit.addEdit(edit);
compoundEdit.end();
undoManager.addEdit(edit);
compoundEdit=null;
//update undo/redo buttons
buttonsUpdate();
}I don't have ideas to solve this problem. Help me, please...I don't have ideas to solve this problem. Help me, please...Based on the random code you posted, neither do I.
My my last posting in this thread will work for you:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637225 -
Still not fixed in CS6: Undo problem after Text Type + Move
I have noticed this very annoying Photoshop problem still has not been addressed by Adobe.
Breakdown:
Type text
Move text
If you undo the move, it will not only undo the move - but the text you typed as well
So technically it does 2 undos instead of just 1. Does this not irritate anybody else? It's so annoying.Type text
Move text
If you undo the move, it will not only undo the move - but the text you typed as well
Between "Type Text" and "Move Text" are you clicking the Check Mark to commit text (or hitting Enter on numeric pad), then selecting the Move Tool to move the text? -
Syntax Highlighting and Undo Problem
Hello Guys. I am working ona very simple type of Java Code Editor with syntax highlighting feature. It works fine as far as the syntax highlighting, cut, copy, paste etc are concerned but when I added Undo, Redo feature, it was not working as Undo Redo should. The UndoManager first removes the text attributes and finally the main Undo job. For example if I paste word public , the UndoManager will first remove the attributes and after about third or fouth click on the Undo button removes the pasted word.
Please Help.Here's the complete demo code.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.text.rtf.*;
import javax.swing.undo.*;
class ColorTextInTextPane extends JFrame implements UndoableEditListener
private Hashtable keywords,impclasses;
JEditorPane edit;
UndoManager undo;
JButton undoIt, redoIt;
JPanel southButtonPanel;
MyDocument doc = new MyDocument();
public ColorTextInTextPane()
super("ColorTextInTextPane");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
edit = new JEditorPane();
edit.setEditorKit(new StyledEditorKit());
edit.setEditable(true);
doc.addUndoableEditListener(this);
edit.setDocument(doc);
JScrollPane scroll=new JScrollPane(edit);
undo = new UndoManager();
undoIt = new JButton("Undo");
undoIt.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
undoAction(ae);
redoIt = new JButton("Redo");
redoIt.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
redoAction(ae);
southButtonPanel = new JPanel();
southButtonPanel.add(undoIt);
southButtonPanel.add(redoIt);
getContentPane().add(scroll);
getContentPane().add(southButtonPanel, BorderLayout.SOUTH);
setSize(300,300);
setVisible(true);
Object dummyObject = new Object();
keywords = new Hashtable();
keywords.put( "abstract", dummyObject );
keywords.put( "boolean", dummyObject );
keywords.put( "break", dummyObject );
keywords.put( "byte", dummyObject );
keywords.put( "byvalue", dummyObject );
keywords.put( "case", dummyObject );
keywords.put( "cast", dummyObject );
keywords.put( "catch", dummyObject );
keywords.put( "char", dummyObject );
keywords.put( "class", dummyObject );
keywords.put( "const", dummyObject );
keywords.put( "continue", dummyObject );
keywords.put( "default", dummyObject );
keywords.put( "do", dummyObject );
keywords.put( "double", dummyObject );
keywords.put( "else", dummyObject );
keywords.put( "extends", dummyObject );
keywords.put( "false", dummyObject );
keywords.put( "final", dummyObject );
keywords.put( "finally", dummyObject );
keywords.put( "float", dummyObject );
keywords.put( "for", dummyObject );
keywords.put( "future", dummyObject );
keywords.put( "generic", dummyObject );
keywords.put( "goto", dummyObject );
keywords.put( "if", dummyObject );
keywords.put( "implements", dummyObject );
keywords.put( "import", dummyObject );
keywords.put( "inner", dummyObject );
keywords.put( "instanceof", dummyObject );
keywords.put( "int", dummyObject );
keywords.put( "interface", dummyObject );
keywords.put( "long", dummyObject );
keywords.put( "native", dummyObject );
keywords.put( "new", dummyObject );
keywords.put( "null", dummyObject );
keywords.put( "operator", dummyObject );
keywords.put( "outer", dummyObject );
keywords.put( "package", dummyObject );
keywords.put( "private", dummyObject );
keywords.put( "protected", dummyObject );
keywords.put( "public", dummyObject );
keywords.put( "rest", dummyObject );
keywords.put( "return", dummyObject );
keywords.put( "short", dummyObject );
keywords.put( "static", dummyObject );
keywords.put( "super", dummyObject );
keywords.put( "switch", dummyObject );
keywords.put( "synchronized", dummyObject );
keywords.put( "this", dummyObject );
keywords.put( "throw", dummyObject );
keywords.put( "throws", dummyObject );
keywords.put( "transient", dummyObject );
keywords.put( "true", dummyObject );
keywords.put( "try", dummyObject );
keywords.put( "var", dummyObject );
keywords.put( "void", dummyObject );
keywords.put( "volatile", dummyObject );
keywords.put( "while", dummyObject );
Object dummyObject1 = new Object();
impclasses = new Hashtable();
impclasses.put( "JFrame", dummyObject1);
impclasses.put( "Applet", dummyObject1);
impclasses.put( "JApplet", dummyObject1);
impclasses.put( "JTextField", dummyObject1);
impclasses.put( "JLabel", dummyObject1);
impclasses.put( "JPanel", dummyObject1);
impclasses.put( "JButton", dummyObject1);
public void undoableEditHappened(UndoableEditEvent ev) {
undo.addEdit(ev.getEdit());
updateMenu();
void undoAction(ActionEvent e) {
try {
if (undo.canUndo())
undo.undo();
updateMenu();
catch (CannotRedoException cre) {
void redoAction(ActionEvent e)
try {
if (undo.canRedo())
undo.redo();
updateMenu();
catch (CannotRedoException cre) {
public void updateMenu()
undoIt.setEnabled(undo.canUndo());
redoIt.setEnabled(undo.canRedo());
public static void main(String a[])
new ColorTextInTextPane();
class MyDocument extends DefaultStyledDocument
DefaultStyledDocument doc;
MutableAttributeSet normal;
MutableAttributeSet keyword;
MutableAttributeSet comment;
MutableAttributeSet quote;
MutableAttributeSet impclasses1;
public MyDocument()
doc = this;
putProperty( DefaultEditorKit.EndOfLineStringProperty, "\n" );
normal = new SimpleAttributeSet();
StyleConstants.setForeground(normal, Color.black);
comment = new SimpleAttributeSet();
StyleConstants.setForeground(comment, Color.green);
StyleConstants.setItalic(comment, true);
keyword = new SimpleAttributeSet();
StyleConstants.setForeground(keyword, Color.blue);
StyleConstants.setBold(keyword, true);
quote = new SimpleAttributeSet();
StyleConstants.setForeground(quote, Color.red);
StyleConstants.setBold(quote, true);
impclasses1 = new SimpleAttributeSet();
StyleConstants.setForeground(impclasses1, Color.magenta);
StyleConstants.setBold(impclasses1, true);
public void insertString(int offset, String str, AttributeSet a) throws BadLocationException
super.insertString(offset, str, a);
processChangedLines(offset, str.length());
public void remove(int offset, int length) throws BadLocationException
super.remove(offset, length);
processChangedLines(offset, 0);
public void processChangedLines(int offset, int length) throws BadLocationException
String content = doc.getText(0, doc.getLength());
Element root = doc.getDefaultRootElement();
int startLine = root.getElementIndex( offset );
int endLine = root.getElementIndex( offset + length );
for (int i = startLine; i <= endLine; i++)
int startOffset = root.getElement( i ).getStartOffset();
int endOffset = root.getElement( i ).getEndOffset();
applyHighlighting(content, startOffset, endOffset - 1);
public void applyHighlighting(String content, int startOffset, int endOffset)
throws BadLocationException
int index;
int lineLength = endOffset - startOffset;
int contentLength = content.length();
if (endOffset >= contentLength)
endOffset = contentLength - 1;
// set normal attributes for the line
doc.setCharacterAttributes(startOffset, lineLength, normal, true);
// check for multi line comment
String multiLineStartDelimiter = "/*";
String multiLineEndDelimiter = "*/";
index = content.lastIndexOf( multiLineStartDelimiter, endOffset );
if (index > -1)
int index2 = content.indexOf( multiLineEndDelimiter, index );
if ( (index2 == -1) || (index2 > endOffset) )
doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
return;
else
if (index2 >= startOffset)
doc.setCharacterAttributes(index, index2 + 2 - index, comment, false);
return;
// check for single line comment
String singleLineDelimiter = "//";
index = content.indexOf( singleLineDelimiter, startOffset );
if ( (index > -1) && (index < endOffset) )
doc.setCharacterAttributes(index, endOffset - index + 1, comment, false);
endOffset = index - 1;
// check for tokens
checkForTokens(content, startOffset, endOffset);
private void checkForTokens(String content, int startOffset, int endOffset)
while (startOffset <= endOffset)
// find the start of a new token
while ( isDelimiter( content.substring(startOffset, startOffset + 1) ) )
if (startOffset < endOffset)
startOffset++;
else
return;
if ( isQuoteDelimiter( content.substring(startOffset, startOffset + 1) ) )
startOffset = getQuoteToken(content, startOffset, endOffset);
else
startOffset = getOtherToken(content, startOffset, endOffset);
private boolean isDelimiter(String character)
String operands = ";:{}()[]+-/%<=>!&|^~*";
if (Character.isWhitespace( character.charAt(0) ) ||
operands.indexOf(character) != -1 )
return true;
else
return false;
private boolean isQuoteDelimiter(String character)
String quoteDelimiters = "\"'";
if (quoteDelimiters.indexOf(character) == -1)
return false;
else
return true;
private boolean isKeyword(String token)
Object o = keywords.get( token );
return o == null ? false : true;
private boolean isimpclasses1(String token)
Object o = impclasses.get( token );
return o == null ? false : true;
private int getQuoteToken(String content, int startOffset, int endOffset)
String quoteDelimiter = content.substring(startOffset, startOffset + 1);
String escapedDelimiter = "\\" + quoteDelimiter;
int index;
int endOfQuote = startOffset;
// skip over the escaped quotes in this quote
index = content.indexOf(escapedDelimiter, endOfQuote + 1);
while ( (index > -1) && (index < endOffset) )
endOfQuote = index + 1;
index = content.indexOf(escapedDelimiter, endOfQuote);
// now find the matching delimiter
index = content.indexOf(quoteDelimiter, endOfQuote + 1);
if ( (index == -1) || (index > endOffset) )
endOfQuote = endOffset;
else
endOfQuote = index;
doc.setCharacterAttributes(startOffset, endOfQuote - startOffset + 1, quote, false);
//String token = content.substring(startOffset, endOfQuote + 1);
//System.out.println( "quote: " + token );
return endOfQuote + 1;
private int getOtherToken(String content, int startOffset, int endOffset)
int endOfToken = startOffset + 1;
while ( endOfToken <= endOffset )
if ( isDelimiter( content.substring(endOfToken, endOfToken + 1) ) )
break;
endOfToken++;
String token = content.substring(startOffset, endOfToken);
//System.out.println( "found: " + token );
if ( isKeyword( token ) )
doc.setCharacterAttributes(startOffset, endOfToken - startOffset, keyword, false);
if(isimpclasses1 ( token) )
doc.setCharacterAttributes(startOffset, endOfToken - startOffset, impclasses1, false);
return endOfToken + 1;
} -
Undo problem - erases more than last step!
Hi,
I've already been going through issues with my own computer (apparently due to an update in Windows my touchpad went haywire, and now using my tablet and mouse does it as well, where clicking and holding that click makes things drag), but somehow Photoshop Elements 7 is being buggy too.
I only noticed it tonight. I will be drawing, and if I draw one line, pull the pen away, draw another connected line and press CTRL+Z or the undo arrow, it erases both lines and not just the previous one like usual. Sometimes CTRL+Z doesn't even work, and I've tested my keys to be responsive. I'm not sure if it is a problem with my computer or actually Photoshop Elem 7. Is there any knowledge of this issue?
Thanks in advance.Click on the word Window and check undo history.
You should then be able to go back one step at a time or at least see how elements is recording each pen step. -
Problem with DefaultStyledDocument.styleChanged(Style)
I have a layout with 'text frames' that contain DefaultStyledDocument's.
I want to do a repaint of a textframe when the underlying paragraph style changes.
The way I do this is that I listen for changes and when a change in a Paragraph Style (StyleContenxt) occur, I do a DefaultStyledDocument.styleChanged( paragraphstyle.getStyle() );
After that I do a repaint() of the component.
All this goes well, and the component is repainted - but not with the new style. It still displays the old style, until I change it or move my mouse over it.
should .styleChanged() and repaint() be sufficient? Can anyone see what is going wrong here?I suppose repaint() is called before all styles are updated. Try to call the repaint() in
SwingUtilities.invokeLater(
new Runnable() {
);Or try to call refresh() of the document.
public void refresh(int offset, int len) {
DefaultDocumentEvent changes = new DefaultDocumentEvent(offset, len, DocumentEvent.EventType.CHANGE);
Element root = getDefaultRootElement();
Element[] removed = new Element[0];
Element[] added = new Element[0];
changes.addEdit(new ElementEdit(root, 0, removed, added));
changes.end();
fireChangedUpdate(changes);
}regards,
Stas -
Undo problem in a java made notepad
i have been working on notepad.i want to provide it features like that provided in MS-DOS TURBO C++.i.e. all the steps can be reversed.
can anybody tell me how to solve this problem in easiest way.I HAVE TWO SOLUTIONS BUT THEY DON'T SATISFY MY MIND.THEY ARE CUMBERSOMEi have been working on notepad.i want to provide it
features like that provided in MS-DOS TURBO C++.i.e.
all the steps can be reversed.
can anybody tell me how to solve this problem in
easiest way.I HAVE TWO SOLUTIONS BUT THEY DON'T
SATISFY MY MIND.THEY ARE CUMBERSOMEWould you tell the solutions you have in your mind? It might be possible that I would be thinking of the same, but let's hear it from you. :)
And post any code if you have written. -
Why can't I undo a big mistake renaming folders--help my library's wrecked
I was backing up a CD we bought for the kids to learn spanish. I multiple edited all of the album's details to call it spanish cd and after I pressed enter a box appeared that said it was processing, and to my horror all the names of my whole itunes library appeared momentarily as they got worked over. Now my whole library is called 'spanish cd' and no albums are together anymore. I tried to undo the action but cannot. Can anybody pLEEEZE help me. I feel that I will have to reload sixty + CDs. Help, help, help. SOS.
Aidan. PS I tried to unchech boxes that say itunes should arrange folders as one entry on the forum seemed to be saying this causes 'undo' problems in other ways. NO result. Help!!!!
Thankyou.iTunes does not have an undo feature and will not necessarily warn you that you are about to do something catastrophic.
If you have the files on an iPod then you could recover them complete with correct tags using methods in this post from Zevoneer: http://discussions.apple.com/thread.jspa?messageID=6273675�
Failing that, you could try MusicBrainz PicardTagger. This is supposed to be able to extract an audio fingerprint of your media files and compare them with a database to determine the correct tag info. It works best however when the files are still arranged in related groups.
Unchecking the "Keep iTunes Music folder organised" option now is a horse & stable door scenario. If you'd done that before your mass edit a simple tagging tool could have rebuilt the album titles from each file's folder name.
tt2 -
Crashing, no 'UNDO' when working with Chinese Text
We have a number of users working in InDesign CS4 6.0.3 on Windows XP SP3. When they enter Chinese text into text boxes, frequently their UNDO command is no longer available. This basically renders files unusable. In addition to this, the application will frequently crash when working with Chinese text. The only workarounds that have sometimes worked include:
1. Switching keyboard mapping or just selecting English to see if it affects the Undo function.
2. Reset the preferences for InDesign.
3. UNDO problem occurred when jumping between web browser and InDesign. Workaround was to select a menu item from within InDesign - any menu item, it didn't matter - and the key command began working again.
Has anybody else run into these problems?Peter, have you had any problems accessing the web pages for the Release Notes? After finally digging under about 3 layers of redundant links (annoying in and of itself), the final links to Release Notes for InDesign patches 6.0.4, 6.0.5, and 6.0.6 brought me to the following:
InDesign 6.0.4 took me to InCopy 6.0.5
InDesign 6.0.5 took me to InCopy 6.0.6
InDesign 6.0.6 took me to InDesign Server CS5
I got approval to install all patches on a person's computer, but now I can't even read the warnings before doing so! -
Undo shortcut intermittently doesn't work
Hi guys,
On certain files §¶•ªªº––≠≠–º•¶§∞¢£™¡¡¡` ¡`` œ∑´®†¥¨ˆøππ“‘«
PS CS5
Mac 10.6.6
16gb RAMYep, it is fully updated. I¹ve already tried throwing away my preferences,
yet the ³undo² problem happened again. I¹ve re-started, repaired
permissions and etc. I should tell you that I can undo, just not with the
keyboard shortcut. Nor, when the shortcut problem comes up, will my mouse
scroll wheel make the contents of a palette go north and south. Another
weird thing that has happened once or twice is that the image thumbnails in
the layers palette have not displayed the mask, in both adjustment and image
layers, after I¹ve used a brush of any kind. Instead, the thumbnail of the
mask will look like the gray and white checkerboard that transparent layers
show. I can get the thumbnail mask to come back if I click several times on
adjacent thumbnails. It kind of seems that PS is running too slowly to
re-write the thumbnail immediately, which doesn¹t make sense because the
MacPro is a 2.93ghz eight core running 16gb of RAM. The file sizes I work
on vary from 30mb to 500mb or so not too huge, though I think the ones
that have the problems I¹ve described are on the larger side. I¹ve got it
set for 25 history states, which ought to be ok.
Another odd thing. I often have 2-4 images open at a time, and the problems
will only be happening to one of those images. On all the other images the
shortcuts, scroll wheel, thumbnails are all ok. Any ideas what the hell is
going on here?
Thank you very much for your help,
Todd Pearson
http://www.toddpearsonphotography.com/
c.pfaffenbichler2/24/11 11:56 [email protected]
Is Photoshop fully updated?
(boilerplate-text) As with all unexplainable Photoshop-problems you might try
trashing the prefs (after making sure all customized presets like Actions,
Patterns, Brushes etc. have been saved and making a note of the Preferences
you¹ve changed) by pressing command-alt-shift on starting the program or
starting from a new user-account.
System Maintenance (repairing permissions, purging PRAM, running cron-scripts,
cleaning caches, etc.) might also be beneficial, Onyx has been recommended for
such tasks.
http://www.apple.com/downloads/macosx/system_disk_utilities/onyx.html
Weeding out bad fonts never seems to be a bad idea, either. (Validate your
fonts in Font Book and remove the bad ones.)
If 3rd party plug-ins are installed try disabling them to verify if one of
those may be responsible for the problem.
> -
Ctrl-F key presses fill up undo buffer
I recently discovered a perplexing issue in Final Cut Pro.
The Ctrl-Fkey transport keys apparently are considered actions
by FCP and hence occupy the undo buffer. Using these keys
to shuttle the timeline will effectively wipe out any important actions
previously stored in the undo buffer and replace them with blank
key presses.
Probably not many people use these keys for that purpose however,
some devices do such as the Bella Professional editor's keyboard.
It has a jog/shuttle wheel built in that is configured to use these
very key presses.
Is there anyone who has noticed this behavior or has been able
to resolve it? Incidentally, to use these keys as FCP designates, one
must turn off Keyboard Navigation in the Keyboard & Mouse pref panel
since they are already assigned by the OS.
Dual processor G5 Mac OS X (10.4.8)Steve, the ShuttlePro looks like a terrific
controller.
To be honest I don't think the design of the shuttle knob is that great, and I don't end up using it as much as I thought I would. It's nothing like the real edit controller shuttles of yore.
By speed select keys are you referring to the J and L
keys or the Ctrl-Fkey's?
I meant the key combos that set a specific speed. As above, thinking I would use the shuttle more I set them to speeds I would actually use - skipping ones that weren't useful to me. It was a lot of work which I'll go undo now...
It WOULD be great to have slow frame by frame play
(JK and KL) on the shuttle as well but like you've
already said, apparently it is unique to those
particular keys.
As long as you map to the actual J K and L keys from buttons you can press individually, it works. It doesn't work with the ShuttlePro knob simply because they only allow one button press to be programmed for each position.
My problem was that I had mapped the ShuttlePro buttons and their functions to new places on the keyboard. The JK and KL functions seem to only work when you're mapping to those actual keys. So I have J K & L mapped to buttons on the ShuttlePro (their default, actually) and it works great.
What really disappoints me is that FCP doesn't support a range of playback speeds that would allow something approximating shuttle behavior.
Thanks for bringing the Undo problem to our attention! -
Split paragraph in DefaultStyledDocument...please help!!
Hi all java guru....
i have a problem with DefaultStyledDocument. i would like to split a paragraph, adding a new line in such way:
this is a paragraph that .......\n
speak about split paragraph
supposing that this paragraph have a ALIGN_LEFT. When i try to do this i get the following problem:
1) if paragraph have an alignment, then after inserted NEWLINE the following text doesn't maintain correct alignment, or rather the alignment of parent paragraph;
2) (i think 1 is a effect of 2) when i attempt to read content of DefaultStyledDocument i get that it has 2 paragraph element in which 1st have "this is a paragraph that .......\n" as a content element and 2nd have "speak about split paragraph" as a content element.
then adding a new line and after text means create a new paragraph with default alignment attribute. I would like to know (if possible) how i can split a paragraph inserting a new line in such way to have a corresponding element, that is a paragraph element with 2 child content elements.
Taking back to html , it should be as follow:
My target -> <p> This is my
paragraph </p>
i get -> <p> This is my \n </p>
<p> paragraph </p>There is no documentation about ParagraphView. I have researched it using source code.
As for breaks.
main loginc is following.
Paragraph goes through all children (LabelViews) and ask their break weight. It's necessary to wrap by spaces and for many other reasons.
There are 4 general kinds of view weight.
0 - no break
1000 good break weight
2000 excellent break weight
3000 forced break weight.
See appropriate constants of View class.
forced break weight means that you paragraph MUST break row and start next one.
You should override method of LabelView like this.
public int getBreakWeight(int axis, float pos, float len) {
int start = this.getStartOffset();
int length = getGlyphPainter().getBoundedPosition(this, start, pos, len) - start;
String text = "";
try {
text = this.getElement().getDocument().getText(start, length);
if (text.indexOf('\r') >= 0) {
return ForcedBreakWeight;
else {
return super.getBreakWeight();
catch (Exception ex) {}
regards,
Stas -
Apply change of style on DefaultStyledDocument
Hi All,
I have problem with DefaultStyledDocument. I want change attribute of some style and apply changes on text, that was written by this style. I can get style by the metod getStyle(String name) and change attribute by the metod StyleConstants.setForeground(style, color). May somebody tell me, how I must apply change on document? Thanks.camickr wrote:
If you change the attributes of an existing Style then you should just repaint() the text pane.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.
Thanks for your reaction. I am sorry, ok here is some example:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.awt.GridBagLayout;
import java.util.Enumeration;
import javax.swing.JButton;
public class TestStyle extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JScrollPane jScrollPane = null;
private JTextPane jTextPane = null;
private Style attrs[] = new Style[2]; // @jve:decl-index=0:
private DefaultStyledDocument doc;
private JPanel jPanel = null;
private JButton jButton = null;
public TestStyle() {
super();
initialize();
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJScrollPane(), BorderLayout.CENTER);
jContentPane.add(getJPanel(), BorderLayout.NORTH);
return jContentPane;
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTextPane());
return jScrollPane;
private JPanel getJPanel() {
if (jPanel == null) {
jPanel = new JPanel();
jPanel.setLayout(new FlowLayout());
jPanel.add(getJButton(), null);
return jPanel;
private JTextPane getJTextPane() {
if (jTextPane == null) {
jTextPane = new JTextPane();
String text = "This is some text witch will be changed.\n"
+ "And next line...";
int len = text.length();
doc = (DefaultStyledDocument) jTextPane.getStyledDocument();
Style def = StyleContext.getDefaultStyleContext().getStyle(
StyleContext.DEFAULT_STYLE);
attrs[0] = doc.addStyle("one", def);
attrs[1] = doc.addStyle("two", def);
StyleConstants.setForeground(attrs[1], Color.red);
doc.addStyle("one", attrs[0]);
StyleConstants.setForeground(attrs[0], Color.blue);
doc.addStyle("two", attrs[1]);
try {
doc.insertString(0, text, attrs[0]);
doc.insertString(len, "This is default style. ", null);
doc.insertString(doc.getLength(), "And this is red style.",
attrs[1]);
} catch (BadLocationException e) {
e.printStackTrace();
return jTextPane;
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton("Change");
//change attribute (don't work)
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Style s = doc.getStyle("one");
System.out.println(s);
StyleConstants.setForeground(s, Color.green);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jTextPane.repaint();
return jButton;
public static void main(String[] arg) {
new TestStyle();
}If I press the Change button blue text should change its color on green, but it isn't work.
Maybe you are looking for
-
When including multiple Criteria in the "Rows" section of Pivot Table we get a desired format of Pivot Table in BI Analytics Answers. However, when creating a Pivot Table in a BI Publisher Template, Adding multiple measures in "Rows" results in the c
-
Hi. How can I get the SystemRoot value for Windows in Java code. There used to be methods to retrieve the value of an environment variable, but they're now deprecated. So, how can I get the value? Thank you. :)
-
H All, We are on data load performance tuning. Here in our Ecc 6.0 production system by SE11 indexes were created for tables on 2008 and data is loading from 2009 full daily. Is it ok by creating indexes for fields of tables before loading and On wha
-
Error running batch files from java source file???
Dear Friends, hi, this is with response to a doubt i had earlier , i want to run batch files from the java source file ,i tried using this code (here batrun is the batch file name that contains commands to run other java files) try String [] command
-
Error -36 connecting to Windows 2000 Server
I'm trying to connect to a windows 2000 server that appears in my Network browser but I can't authenticate using the Network browser or via smb://. I have been able to connect in the past no problem and I can login to the server on another machine us