Changeset 30735 in osm for applications/editors/josm/plugins/imagery-xml-bounds/src/net
- Timestamp:
- 2014-10-18T20:09:04+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlEditorKit.java
r26776 r30735 19 19 import javax.swing.text.ViewFactory; 20 20 21 22 21 /** 23 22 * @author kees 24 23 * @date 12-jan-2006 25 *26 24 */ 27 25 public class XmlEditorKit extends StyledEditorKit { … … 30 28 private ViewFactory xmlViewFactory; 31 29 30 /** 31 * Constructs a new {@code XmlEditorKit}. 32 */ 32 33 public XmlEditorKit() { 33 34 xmlViewFactory = new XmlViewFactory(); 34 35 } 35 36 36 37 @Override 37 38 public ViewFactory getViewFactory() { … … 43 44 return "text/xml"; 44 45 } 45 46 47 46 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlTextPane.java
r26776 r30735 24 24 import javax.swing.text.BadLocationException; 25 25 26 import net.boplicity.xmleditor.XmlEditorKit;27 28 26 29 27 /** 30 28 * JTextPane implementation that can handle xml text. The IndentKeyListener 31 29 * implements smart indenting. 32 * 30 * 33 31 * @author kees 34 32 * @date 27-jan-2006 … … 37 35 public class XmlTextPane extends JTextPane { 38 36 39 private static final long serialVersionUID = 6270183148379328084L;40 private Logger logger = Logger.getLogger(getClass().getName());37 private static final Logger LOGGER = Logger.getLogger(XmlTextPane.class.getName()); 38 private static final Character NEW_LINE = '\n'; 41 39 40 /** 41 * Constructs a new {@code XmlTextPane}. 42 */ 42 43 public XmlTextPane() { 43 44 44 45 // Set editor kit 45 46 this.setEditorKitForContentType("text/xml", new XmlEditorKit()); 46 47 this.setContentType("text/xml"); 47 48 48 49 addKeyListener(new IndentKeyListener()); 49 50 } 50 51 private class IndentKeyListener implements KeyListener {52 51 53 private boolean enterFlag; 54 private final Character NEW_LINE = '\n'; 52 private class IndentKeyListener implements KeyListener { 55 53 56 public void keyPressed(KeyEvent event) { 57 enterFlag = false; 58 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 59 && (event.getModifiers() == 0)) { 60 if (getSelectionStart() == getSelectionEnd()) { 61 enterFlag = true; 62 event.consume(); 63 } 64 } 65 } 54 private boolean enterFlag; 66 55 67 public void keyReleased(KeyEvent event) { 68 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 69 && (event.getModifiers() == 0)) { 70 if (enterFlag) { 71 event.consume(); 56 @Override 57 public void keyPressed(KeyEvent event) { 58 enterFlag = false; 59 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 60 && (event.getModifiers() == 0) 61 && getSelectionStart() == getSelectionEnd()) { 62 enterFlag = true; 63 event.consume(); 64 } 65 } 72 66 73 int start, end; 74 String text = getText(); 67 @Override 68 public void keyReleased(KeyEvent event) { 69 if ((event.getKeyCode() == KeyEvent.VK_ENTER) 70 && (event.getModifiers() == 0) && enterFlag) { 71 event.consume(); 75 72 76 int caretPosition = getCaretPosition(); 77 try { 78 if (text.charAt(caretPosition) == NEW_LINE) { 79 caretPosition--; 80 } 81 } catch (IndexOutOfBoundsException e) { 82 } 73 int start, end; 74 String text = getText(); 83 75 84 start = text.lastIndexOf(NEW_LINE, caretPosition) + 1; 85 end = start; 86 try { 87 if (text.charAt(start) != NEW_LINE) { 88 while ((end < text.length()) 89 && (Character 90 .isWhitespace(text.charAt(end))) 91 && (text.charAt(end) != NEW_LINE)) { 92 end++; 93 } 94 if (end > start) { 95 getDocument() 96 .insertString( 97 getCaretPosition(), 98 NEW_LINE 99 + text.substring(start, 100 end), null); 101 } else { 102 getDocument().insertString(getCaretPosition(), 103 NEW_LINE.toString(), null); 104 } 105 } else { 106 getDocument().insertString(getCaretPosition(), 107 NEW_LINE.toString(), null); 108 } 109 } catch (IndexOutOfBoundsException e) { 110 try { 111 getDocument().insertString(getCaretPosition(), 112 NEW_LINE.toString(), null); 113 } catch (BadLocationException e1) { 114 logger.log(Level.WARNING, e1.toString()); 115 } 116 } catch (BadLocationException e) { 117 logger.log(Level.WARNING, e.toString()); 118 } 119 } 120 } 121 } 76 int caretPosition = getCaretPosition(); 77 try { 78 if (text.charAt(caretPosition) == NEW_LINE) { 79 caretPosition--; 80 } 81 } catch (IndexOutOfBoundsException e) { 82 LOGGER.log(Level.FINE, e.toString()); 83 } 122 84 123 public void keyTyped(KeyEvent e) { 124 } 125 } 126 85 start = text.lastIndexOf(NEW_LINE, caretPosition) + 1; 86 end = start; 87 try { 88 if (text.charAt(start) != NEW_LINE) { 89 while ((end < text.length()) 90 && (Character.isWhitespace(text.charAt(end))) 91 && (text.charAt(end) != NEW_LINE)) { 92 end++; 93 } 94 if (end > start) { 95 getDocument() 96 .insertString( 97 getCaretPosition(), 98 NEW_LINE 99 + text.substring(start, 100 end), null); 101 } else { 102 getDocument().insertString(getCaretPosition(), 103 NEW_LINE.toString(), null); 104 } 105 } else { 106 getDocument().insertString(getCaretPosition(), 107 NEW_LINE.toString(), null); 108 } 109 } catch (IndexOutOfBoundsException e) { 110 try { 111 getDocument().insertString(getCaretPosition(), 112 NEW_LINE.toString(), null); 113 } catch (BadLocationException e1) { 114 LOGGER.log(Level.WARNING, e1.toString()); 115 } 116 } catch (BadLocationException e) { 117 LOGGER.log(Level.WARNING, e.toString()); 118 } 119 } 120 } 121 122 @Override 123 public void keyTyped(KeyEvent e) { 124 // Do nothing 125 } 126 } 127 127 } -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlView.java
r26776 r30735 18 18 import java.awt.Color; 19 19 import java.awt.Graphics; 20 import java.util.HashMap;21 20 import java.util.LinkedHashMap; 22 21 import java.util.Map; … … 47 46 public class XmlView extends PlainView { 48 47 49 private static HashMap<Pattern, Color> patternColors;48 private static Map<Pattern, Color> patternColors; 50 49 private static String GENERIC_XML_NAME = "[A-Za-z]+[A-Za-z0-9\\-_]*(:[A-Za-z]+[A-Za-z0-9\\-_]+)?"; 51 50 private static String TAG_PATTERN = "(</?" + GENERIC_XML_NAME + ")"; … … 58 57 static { 59 58 // NOTE: the order is important! 60 patternColors = new LinkedHashMap< Pattern, Color>();59 patternColors = new LinkedHashMap<>(); 61 60 patternColors 62 61 .put(Pattern.compile(TAG_PATTERN), new Color(63, 127, 127)); … … 71 70 } 72 71 72 /** 73 * Constructs a new {@code XmlView}. 74 * @param element the element 75 */ 73 76 public XmlView(Element element) { 74 77 … … 80 83 81 84 @Override 82 protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, 83 int p1)throws BadLocationException {85 protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) 86 throws BadLocationException { 84 87 85 88 Document doc = getDocument(); … … 88 91 Segment segment = getLineBuffer(); 89 92 90 SortedMap<Integer, Integer> startMap = new TreeMap< Integer, Integer>();91 SortedMap<Integer, Color> colorMap = new TreeMap< Integer, Color>();93 SortedMap<Integer, Integer> startMap = new TreeMap<>(); 94 SortedMap<Integer, Color> colorMap = new TreeMap<>(); 92 95 93 96 // Match all regexes on this snippet, store positions -
applications/editors/josm/plugins/imagery-xml-bounds/src/net/boplicity/xmleditor/XmlViewFactory.java
r26776 r30735 20 20 import javax.swing.text.ViewFactory; 21 21 22 23 22 /** 24 23 * @author kees … … 28 27 public class XmlViewFactory extends Object implements ViewFactory { 29 28 30 /** 31 * @see javax.swing.text.ViewFactory#create(javax.swing.text.Element) 32 */ 29 @Override 33 30 public View create(Element element) { 34 35 31 return new XmlView(element); 36 32 } 37 38 33 }
Note:
See TracChangeset
for help on using the changeset viewer.