branch develop updated (50c8c53 -> c63b675)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git from 50c8c53 acept files whose extension is upper case adds 6b944fe refs #3655 amélioration du masque de saisie adds 79234ec refs #3655 il manque pour dd le dernier component adds 47e023f refs #3655 ajout de classes pour tester le composant new 74be8e0 refs #3655 deplace le code pour pouvoir le reutiliser dans d'autres contextes new c63b675 fixes #3656: Introduce a API to navigate inside a JFormattedTextField using a mask fixes #3655: [AbsoluteCoordinateEditor] Improve navigation of a coordinate Merge branch 'feature/3655' into develop The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit c63b6756d47a140dc9abfa94dcdce4005fff75c6 Merge: 50c8c53 74be8e0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Mar 21 11:44:13 2015 +0100 fixes #3656: Introduce a API to navigate inside a JFormattedTextField using a mask fixes #3655: [AbsoluteCoordinateEditor] Improve navigation of a coordinate Merge branch 'feature/3655' into develop why this merge is necessary, commit 74be8e0892b22950d8b7ac73f1cf95253f9c278b Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Mar 21 11:31:40 2015 +0100 refs #3655 deplace le code pour pouvoir le reutiliser dans d'autres contextes Summary of changes: .../JFormattedTextFieldNavigationManager.java | 346 +++++++++++++++++++++ .../JFormatterTextFieldInternalGroup.java | 92 ++++++ .../JFormatterTextFieldInternalGroups.java | 130 ++++++++ jaxx-widgets-gis/pom.xml | 6 + .../gis/absolute/AbsoluteDdCoordinateEditor.jaxx | 4 +- .../AbsoluteDdCoordinateEditorHandler.java | 3 + .../AbsoluteDmdCoordinateEditorHandler.java | 3 + .../AbsoluteDmsCoordinateEditorHandler.java | 3 + .../absolute/AbsoluteDdCoordinateEditorTest.java | 116 +++++++ .../absolute/AbsoluteDmsCoordinateEditorTest.java | 125 ++++++++ .../src/test/resources/log4j.properties | 1 + 11 files changed, 827 insertions(+), 2 deletions(-) create mode 100644 jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java create mode 100644 jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroup.java create mode 100644 jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroups.java create mode 100644 jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorTest.java create mode 100644 jaxx-widgets-gis/src/test/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorTest.java -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git commit 74be8e0892b22950d8b7ac73f1cf95253f9c278b Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Mar 21 11:31:40 2015 +0100 refs #3655 deplace le code pour pouvoir le reutiliser dans d'autres contextes --- .../JFormattedTextFieldNavigationManager.java | 337 +++++++++++++++++++++ .../JFormatterTextFieldInternalGroup.java | 92 ++++++ .../JFormatterTextFieldInternalGroups.java | 130 ++++++++ jaxx-widgets-gis/pom.xml | 6 + .../widgets/gis/CoordinateComponentPosition.java | 78 ----- .../widgets/gis/CoordinateComponentPositions.java | 292 ------------------ .../AbsoluteDdCoordinateEditorHandler.java | 5 +- .../AbsoluteDmdCoordinateEditorHandler.java | 5 +- .../AbsoluteDmsCoordinateEditorHandler.java | 5 +- .../src/test/resources/log4j.properties | 2 +- 10 files changed, 572 insertions(+), 380 deletions(-) diff --git a/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java new file mode 100644 index 0000000..e563722 --- /dev/null +++ b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java @@ -0,0 +1,337 @@ +package org.nuiton.jaxx.widgets.jformattedtextfield; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JFormattedTextField; +import javax.swing.SwingUtilities; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.HashMap; +import java.util.Map; + +/** + * Manager to navigate inside a JFormattedTextField using a MaskFormatter. + * + * Created on 3/21/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.23 + */ +public class JFormattedTextFieldNavigationManager { + + /** Logger. */ + private static final Log log = LogFactory.getLog(JFormattedTextFieldNavigationManager.class); + + private static final String CLIENT_PROPERTY_NAVIGATION_MANAGER = "JFormattedTextFieldNavigationHandler"; + + public static void install(String pattern, JFormattedTextField component) { + + JFormatterTextFieldInternalGroups componentPositions = JFormatterTextFieldInternalGroups.create(pattern); + + JFormattedTextFieldNavigationManager handler = new JFormattedTextFieldNavigationManager(componentPositions, component); + component.putClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER, handler); + handler.install0(component); + + } + + public static void uninstall(JFormattedTextField component) { + + JFormattedTextFieldNavigationManager handler = (JFormattedTextFieldNavigationManager) component.getClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER); + try { + handler.uninstall0(component); + } finally { + component.putClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER, null); + } + + } + + private final JFormatterTextFieldInternalGroups groups; + + private final KeyAdapter keyAdapter; + + private final MouseAdapter mouseAdapter; + + private final FocusAdapter focusAdapter; + + private final Map<JFormatterTextFieldInternalGroup, SelectComponentAction> actions; + + private JFormatterTextFieldInternalGroup lastGroup = null; + + protected JFormattedTextFieldNavigationManager(JFormatterTextFieldInternalGroups groups, JFormattedTextField component) { + + this.groups = groups; + + this.actions = new HashMap<JFormatterTextFieldInternalGroup, SelectComponentAction>(); + for (JFormatterTextFieldInternalGroup componentPosition : groups) { + actions.put(componentPosition, new SelectComponentAction(component, componentPosition)); + } + + this.keyAdapter = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + int caretPosition = source.getCaretPosition(); + + if (canGoRight(e)) { + + goRight(source, caretPosition); + e.consume(); + + } else if (canTransferFocus(e)) { + + source.transferFocus(); + e.consume(); + + } else if (canGoLeft(e)) { + + goLeft(source, caretPosition); + e.consume(); + + } else if (canTransferFocusBackward(e)) { + + source.transferFocusBackward(); + e.consume(); + + } + + } + + @Override + public void keyReleased(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + + }; + + this.mouseAdapter = new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + }; + + this.focusAdapter = new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + + lastGroup = null; + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + }; + + } + + protected void gotoComponent(JFormattedTextField source, JFormatterTextFieldInternalGroup group) { + + if (group != null) { + + int startIndex = group.getStartIndex(); + int endIndex = group.getEndIndex(); + if (log.isDebugEnabled()) { + log.debug(String.format("Goto component [%s - %s]", startIndex, endIndex)); + } + source.setCaretPosition(startIndex); + + } + + } + + protected void selectComponent(JFormatterTextFieldInternalGroup currentGroup) { + + if (lastGroup == null || !lastGroup.equals(currentGroup)) { + + if (log.isDebugEnabled()) { + log.debug("New select group: " + currentGroup); + } + lastGroup = currentGroup; + + SelectComponentAction action = actions.get(currentGroup); + SwingUtilities.invokeLater(action); + + } + + } + + protected JFormatterTextFieldInternalGroup getCurrentGroup(JFormattedTextField source) { + + int caretPosition = source.getCaretPosition(); + return groups.getGroupAtPosition(caretPosition); + + } + + protected void goRight(JFormattedTextField source, int caretPosition) { + + if (lastGroup == null || !lastGroup.isLastGroup()) { + + if (log.isDebugEnabled()) { + log.debug("Go right from position " + caretPosition); + } + JFormatterTextFieldInternalGroup currentGroup = groups.getGroupAtPosition(caretPosition); + JFormatterTextFieldInternalGroup nextGroup = currentGroup.getNextGroup(); + gotoComponent(source, nextGroup); + + } + + } + + protected void goLeft(JFormattedTextField source, int caretPosition) { + + if (lastGroup == null || !lastGroup.isFirstGroup()) { + + if (log.isDebugEnabled()) { + log.debug("Go left from position " + caretPosition); + } + JFormatterTextFieldInternalGroup currentGroup = groups.getGroupAtPosition(caretPosition); + JFormatterTextFieldInternalGroup nextGroup = currentGroup.getPreviousGroup(); + gotoComponent(source, nextGroup); + + } + } + + + protected boolean canGoRight(KeyEvent e) { + + boolean result = false; + + boolean noModifiers = e.getModifiers() == 0; + + if (KeyEvent.VK_RIGHT == e.getKeyCode() && noModifiers) { + + // right key go to next component + result = true; + + } else if (KeyEvent.VK_TAB == e.getKeyCode() && noModifiers) { + + // Tab go to next component if not on last one + result = lastGroup == null || !lastGroup.isLastGroup(); + + } + + return result; + + } + + protected boolean canGoLeft(KeyEvent e) { + + boolean result = false; + + if (KeyEvent.VK_LEFT == e.getKeyCode() && e.getModifiers() == 0) { + + // Left key go to previous component + result = true; + + } else if (KeyEvent.VK_TAB == e.getKeyCode() && e.isShiftDown() && !e.isControlDown()) { + + // Shift Tab go to previous component if not on first one + result = lastGroup != null && !lastGroup.isFirstGroup(); + + } + + return result; + + } + + protected boolean canTransferFocus(KeyEvent e) { + + boolean result = false; + + boolean onTabKey = KeyEvent.VK_TAB == e.getKeyCode(); + + if (onTabKey && e.isControlDown() && !e.isShiftDown()) { + + // Ctrl Tab go direct to focus + result = true; + + } else if (onTabKey && e.getModifiers() == 0) { + + // Tab on last component go to focus + result = lastGroup != null && lastGroup.isLastGroup(); + + } + + return result; + + } + + protected boolean canTransferFocusBackward(KeyEvent e) { + + boolean result = false; + + boolean onShiftTabKey = KeyEvent.VK_TAB == e.getKeyCode() && e.isShiftDown(); + + if (onShiftTabKey && e.isControlDown()) { + + // Ctrl Shift Tab go direct to focus backward + result = true; + + } else if (onShiftTabKey) { + + // Shit Tab go to focus backward only if no component selected or on the first one + result = lastGroup == null || lastGroup.isFirstGroup(); + + } + + return result; + + } + + private void install0(JFormattedTextField component) { + + component.setFocusTraversalKeysEnabled(false); + component.addKeyListener(keyAdapter); + component.addMouseListener(mouseAdapter); + component.addFocusListener(focusAdapter); + } + + private void uninstall0(JFormattedTextField component) { + + component.setFocusTraversalKeysEnabled(true); + component.removeKeyListener(keyAdapter); + component.removeMouseListener(mouseAdapter); + component.removeFocusListener(focusAdapter); + + } + + private static class SelectComponentAction implements Runnable { + + private final JFormatterTextFieldInternalGroup group; + + private final JFormattedTextField source; + + private SelectComponentAction(JFormattedTextField source, JFormatterTextFieldInternalGroup group) { + this.group = group; + this.source = source; + } + + @Override + public void run() { + + int startIndex = group.getStartIndex(); + int endIndex = group.getEndIndex() + 1; + if (log.isDebugEnabled()) { + log.debug(String.format("Select group [%s]", group)); + } + source.select(startIndex, endIndex); + + } + } + +} diff --git a/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroup.java b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroup.java new file mode 100644 index 0000000..93e8ce7 --- /dev/null +++ b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroup.java @@ -0,0 +1,92 @@ +package org.nuiton.jaxx.widgets.jformattedtextfield; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import javax.swing.JFormattedTextField; +import javax.swing.text.MaskFormatter; + +/** + * Represent a group of the mask inside a {@link JFormattedTextField} using a {@link MaskFormatter}. + * + * Created on 3/20/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.23 + */ +public class JFormatterTextFieldInternalGroup { + + /** + * index where the group starts. + */ + private final int startIndex; + + /** + * index where the group ends. + */ + private final int endIndex; + + /** + * index where the group + his symbols ends. + */ + private final int endGroupIndex; + + private JFormatterTextFieldInternalGroup previousGroup; + + private JFormatterTextFieldInternalGroup nextGroup; + + public JFormatterTextFieldInternalGroup(int startIndex, int endIndex, int endGroupIndex) { + this.startIndex = startIndex; + this.endIndex = endIndex; + this.endGroupIndex = endGroupIndex; + } + + public int getStartIndex() { + return startIndex; + } + + public int getEndIndex() { + return endIndex; + } + + public int getEndGroupIndex() { + return endGroupIndex; + } + + public boolean containsPosition(int position) { + return startIndex <= position && position <= endGroupIndex; + } + + public boolean isFirstGroup() { + return previousGroup == null; + } + + public boolean isLastGroup() { + return nextGroup == null; + } + + public JFormatterTextFieldInternalGroup getPreviousGroup() { + return previousGroup; + } + + public JFormatterTextFieldInternalGroup getNextGroup() { + return nextGroup; + } + + public void setPreviousGroup(JFormatterTextFieldInternalGroup previousGroup) { + this.previousGroup = previousGroup; + } + + public void setNextGroup(JFormatterTextFieldInternalGroup nextGroup) { + this.nextGroup = nextGroup; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) + .append("startIndex", startIndex) + .append("endIndex", endIndex) + .append("endGroupIndex", endGroupIndex) + .toString(); + } +} diff --git a/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroups.java b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroups.java new file mode 100644 index 0000000..83e63e3 --- /dev/null +++ b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormatterTextFieldInternalGroups.java @@ -0,0 +1,130 @@ +package org.nuiton.jaxx.widgets.jformattedtextfield; + +import com.google.common.collect.ImmutableSet; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created on 3/20/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.23 + */ +public class JFormatterTextFieldInternalGroups implements Iterable<JFormatterTextFieldInternalGroup> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(JFormatterTextFieldInternalGroups.class); + + public static JFormatterTextFieldInternalGroups create(String mask) { + + // We need to double this caracter for MaskFormatter creation, but here we don't + // TODO See which other caracters must be especad by MaskFormatter + mask = mask.replaceAll("''", "'"); + + Set<JFormatterTextFieldInternalGroup> groups = new LinkedHashSet<JFormatterTextFieldInternalGroup>(); + + JFormatterTextFieldInternalGroup previousGroup = null; + int length = mask.length(); + + for (int i = 0; i < length; i++) { + char c = mask.charAt(i); + if (c != '*') { + + int endIndex = i - 1; + int endGroupIndex = getGroupLastIndex(mask, i, length); + + i = endGroupIndex + 1; + + // new group detected + previousGroup = addGroup(groups, previousGroup, endIndex, endGroupIndex); + + } + + } + + if (previousGroup != null && previousGroup.getEndGroupIndex() < length - 1) { + + // adding the last remaining group + addGroup(groups, previousGroup, length, length); + + } + + JFormatterTextFieldInternalGroups result = new JFormatterTextFieldInternalGroups(groups); + return result; + + } + + protected static int getGroupLastIndex(String mask, int i, int length) { + + do { + + char c2 = mask.charAt(i); + if (c2 == '*') { + break; + } + i++; + + } while (i < length); + + return i - 1; + + } + + protected static JFormatterTextFieldInternalGroup addGroup(Set<JFormatterTextFieldInternalGroup> componentPositions, JFormatterTextFieldInternalGroup previousGroup, int endIndex, int endSymbolIndex) { + + boolean withPreviousGroup = previousGroup != null; + + JFormatterTextFieldInternalGroup newGroup; + + if (withPreviousGroup) { + + newGroup = new JFormatterTextFieldInternalGroup(previousGroup.getEndGroupIndex() + 1, endIndex, endSymbolIndex); + + } else { + + newGroup = new JFormatterTextFieldInternalGroup(0, endIndex, endSymbolIndex); + + } + + if (log.isDebugEnabled()) { + log.debug(String.format("New component (%d): %d - %d - %d", componentPositions.size(), newGroup.getStartIndex(), newGroup.getEndIndex(), newGroup.getEndGroupIndex())); + } + componentPositions.add(newGroup); + if (withPreviousGroup) { + previousGroup.setNextGroup(newGroup); + newGroup.setPreviousGroup(previousGroup); + } + + return newGroup; + + } + + private final Set<JFormatterTextFieldInternalGroup> componentPositions; + + public JFormatterTextFieldInternalGroup getGroupAtPosition(int position) { + + JFormatterTextFieldInternalGroup result = null; + for (JFormatterTextFieldInternalGroup componentPosition : this) { + if (componentPosition.containsPosition(position)) { + result = componentPosition; + break; + } + } + return result; + + } + + protected JFormatterTextFieldInternalGroups(Set<JFormatterTextFieldInternalGroup> componentPositions) { + this.componentPositions = ImmutableSet.copyOf(componentPositions); + } + + @Override + public Iterator<JFormatterTextFieldInternalGroup> iterator() { + return componentPositions.iterator(); + } + +} diff --git a/jaxx-widgets-gis/pom.xml b/jaxx-widgets-gis/pom.xml index caa7360..92affaa 100644 --- a/jaxx-widgets-gis/pom.xml +++ b/jaxx-widgets-gis/pom.xml @@ -60,6 +60,12 @@ <dependency> <groupId>${project.groupId}</groupId> + <artifactId>jaxx-widgets-common</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>jaxx-validator</artifactId> <version>${project.version}</version> </dependency> diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPosition.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPosition.java deleted file mode 100644 index 7ef4636..0000000 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPosition.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.nuiton.jaxx.widgets.gis; - -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * Created on 3/20/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.23 - */ -public class CoordinateComponentPosition { - - /** - * index where the component starts. - */ - private final int startIndex; - - /** - * index where the component ends. - */ - private final int endIndex; - - /** - * index where the component + his symbols ends. - */ - private final int endComponentIndex; - - private CoordinateComponentPosition previousComponent; - - private CoordinateComponentPosition nextComponent; - - public CoordinateComponentPosition(int startIndex, int endIndex, int endComponentIndex) { - this.startIndex = startIndex; - this.endIndex = endIndex; - this.endComponentIndex=endComponentIndex; - } - - public int getStartIndex() { - return startIndex; - } - - public int getEndIndex() { - return endIndex; - } - - public int getEndComponentIndex() { - return endComponentIndex; - } - - public boolean containsPosition(int position) { - return startIndex<= position && position <=endComponentIndex; - } - - public CoordinateComponentPosition getPreviousComponent() { - return previousComponent; - } - - public CoordinateComponentPosition getNextComponent() { - return nextComponent; - } - - public void setPreviousComponent(CoordinateComponentPosition previousComponent) { - this.previousComponent = previousComponent; - } - - public void setNextComponent(CoordinateComponentPosition nextComponent) { - this.nextComponent = nextComponent; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("startIndex", startIndex) - .append("endIndex", endIndex) - .append("endComponentIndex", endComponentIndex) - .toString(); - } -} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPositions.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPositions.java deleted file mode 100644 index 5f5aa39..0000000 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/CoordinateComponentPositions.java +++ /dev/null @@ -1,292 +0,0 @@ -package org.nuiton.jaxx.widgets.gis; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.JFormattedTextField; -import javax.swing.SwingUtilities; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * Created on 3/20/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 2.23 - */ -public class CoordinateComponentPositions { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CoordinateComponentPositions.class); - - public static CoordinateComponentPositions create(String mask) { - - Set<CoordinateComponentPosition> componentPositions = new LinkedHashSet<CoordinateComponentPosition>(); - - CoordinateComponentPosition previousComponent = null; - int length = mask.length(); - for (int i = 0; i < length; i++) { - char c = mask.charAt(i); - if (c != '*') { - - int endIndex = i - 1; - int endSymbolIndex = i; - - do { - - char c2 = mask.charAt(endSymbolIndex); - if (c2 == '*') { - break; - } - endSymbolIndex++; - } while (endSymbolIndex < length); - - i = endSymbolIndex; - endSymbolIndex--; - - // new component detected - CoordinateComponentPosition newComponent; - - if (previousComponent == null) { - - // first component - newComponent = new CoordinateComponentPosition(0, endIndex, endSymbolIndex); - - } else { - - // not first component - newComponent = new CoordinateComponentPosition(previousComponent.getEndComponentIndex() + 1, endIndex, endSymbolIndex); - previousComponent.setNextComponent(newComponent); - newComponent.setPreviousComponent(previousComponent); - - } - - addComponent(componentPositions, newComponent); - previousComponent = newComponent; - - } - - } - - int endComponentIndex = previousComponent.getEndComponentIndex(); - if (endComponentIndex < length-1) { - - // adding the last component - CoordinateComponentPosition newComponent = new CoordinateComponentPosition(previousComponent.getEndComponentIndex() + 1, length, length); - previousComponent.setNextComponent(newComponent); - newComponent.setPreviousComponent(previousComponent); - addComponent(componentPositions, newComponent); - } - - - CoordinateComponentPositions result = new CoordinateComponentPositions(componentPositions, length); - return result; - - } - - protected static void addComponent(Set<CoordinateComponentPosition> componentPositions, CoordinateComponentPosition newComponent) { - - if (log.isInfoEnabled()) { - log.info(String.format("New component (%d): %d - %d - %d", componentPositions.size(), newComponent.getStartIndex(), newComponent.getEndIndex(), newComponent.getEndComponentIndex())); - } - componentPositions.add(newComponent); - } - - private final Set<CoordinateComponentPosition> componentPositions; - - private final int length; - - public CoordinateComponentPosition getComponentPosition(int position) { - - if (position >= length) { - position = length - 1; - } - CoordinateComponentPosition result = null; - for (CoordinateComponentPosition componentPosition : componentPositions) { - if (componentPosition.containsPosition(position)) { - result = componentPosition; - break; - } - } - return result; - - } - - public void installKeyListener(JFormattedTextField component) { - - PositionChangedKeyListener handler = new PositionChangedKeyListener(this); - component.addKeyListener(handler); - component.addMouseListener(handler); - component.addFocusListener(handler); - - } - - protected CoordinateComponentPositions(Set<CoordinateComponentPosition> componentPositions, int length) { - this.componentPositions = componentPositions; - this.length = length; - } - - private static class PositionChangedKeyListener implements KeyListener, MouseListener, FocusListener { - - private final CoordinateComponentPositions componentPositions; - - private CoordinateComponentPosition lastComponentPosition = null; - - public PositionChangedKeyListener(CoordinateComponentPositions componentPositions) { - this.componentPositions = componentPositions; - } - - @Override - public void keyTyped(KeyEvent e) { - - } - - @Override - public void keyPressed(KeyEvent e) { - - JFormattedTextField source = (JFormattedTextField) e.getSource(); - int caretPosition = source.getCaretPosition(); - if (e.getKeyCode() == KeyEvent.VK_RIGHT) { - goRight(source, caretPosition); - - e.consume(); - } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { - goLeft(source, caretPosition); - e.consume(); - } - - } - - @Override - public void keyReleased(KeyEvent e) { - - JFormattedTextField source = (JFormattedTextField) e.getSource(); - int caretPosition = source.getCaretPosition(); - CoordinateComponentPosition currentComponentPosition = componentPositions.getComponentPosition(caretPosition); - if (lastComponentPosition == null || !lastComponentPosition.equals(currentComponentPosition)) { - - lastComponentPosition = currentComponentPosition; - - // component changed - SelectComponentAction action = new SelectComponentAction(currentComponentPosition, source); - action.run(); - - } - - } - - protected void goRight(JFormattedTextField source, int caretPosition) { - - if (log.isDebugEnabled()) { - log.debug("Go right from position " + caretPosition); - } - CoordinateComponentPosition currentComponent = componentPositions.getComponentPosition(caretPosition); - CoordinateComponentPosition nextComponent = currentComponent.getNextComponent(); - gotoComponent(source, nextComponent); - - } - - protected void goLeft(JFormattedTextField source, int caretPosition) { - - if (log.isDebugEnabled()) { - log.debug("Go left from position " + caretPosition); - } - CoordinateComponentPosition currentComponent = componentPositions.getComponentPosition(caretPosition); - CoordinateComponentPosition nextComponent = currentComponent.getPreviousComponent(); - gotoComponent(source, nextComponent); - - } - - protected void gotoComponent(JFormattedTextField source, CoordinateComponentPosition nextComponent) { - if (nextComponent != null) { - - // can go to previous group - int startIndex = nextComponent.getStartIndex(); - int endIndex = nextComponent.getEndIndex(); - if (log.isDebugEnabled()) { - log.debug(String.format("Goto component [%s - %s]", startIndex, endIndex)); - } - source.setCaretPosition(startIndex); - - } - } - - @Override - public void mouseClicked(MouseEvent e) { - lastComponentPosition = null; - - JFormattedTextField source = (JFormattedTextField) e.getSource(); - int caretPosition = source.getCaretPosition(); - CoordinateComponentPosition currentComponentPosition = componentPositions.getComponentPosition(caretPosition); - SelectComponentAction action = new SelectComponentAction(currentComponentPosition, source); - SwingUtilities.invokeLater(action); - } - - @Override - public void focusGained(FocusEvent e) { - - lastComponentPosition = null; - JFormattedTextField source = (JFormattedTextField) e.getSource(); - int caretPosition = source.getCaretPosition(); - CoordinateComponentPosition currentComponentPosition = componentPositions.getComponentPosition(caretPosition); - - SelectComponentAction action = new SelectComponentAction(currentComponentPosition, source); - SwingUtilities.invokeLater(action); - - } - - @Override - public void mousePressed(MouseEvent e) { - - } - - @Override - public void mouseReleased(MouseEvent e) { - - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } - - @Override - public void focusLost(FocusEvent e) { - - } - } - - private static class SelectComponentAction implements Runnable { - - private final CoordinateComponentPosition componentPosition; - - private final JFormattedTextField source; - - private SelectComponentAction(CoordinateComponentPosition componentPosition, JFormattedTextField source) { - this.componentPosition = componentPosition; - this.source = source; - } - - @Override - public void run() { - int startIndex = componentPosition.getStartIndex(); - int endIndex = componentPosition.getEndIndex() + 1; - if (log.isDebugEnabled()) { - log.debug(String.format("Select component [%s]", componentPosition)); - } - source.select(startIndex, endIndex); - } - } - -} diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java index f8981d2..322c856 100644 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java @@ -26,10 +26,10 @@ import com.google.common.base.Preconditions; import jaxx.runtime.spi.UIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.widgets.gis.CoordinateComponentPositions; import org.nuiton.jaxx.widgets.gis.DdCoordinate; import org.nuiton.jaxx.widgets.gis.DdCoordinateConverter; import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; +import org.nuiton.jaxx.widgets.jformattedtextfield.JFormattedTextFieldNavigationManager; import org.nuiton.util.beans.BeanUtil; import javax.swing.JFormattedTextField; @@ -110,8 +110,7 @@ public class AbsoluteDdCoordinateEditorHandler implements UIHandler<AbsoluteDdCo JFormattedTextField editor = ui.getEditor(); - CoordinateComponentPositions componentPositions = CoordinateComponentPositions.create(pattern); - componentPositions.installKeyListener(editor); + JFormattedTextFieldNavigationManager.install(pattern, editor); DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(maskFormatter); editor.setFormatterFactory(formatterFactory); diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java index 7d56bc1..ccd9af0 100644 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java @@ -26,10 +26,10 @@ import com.google.common.base.Preconditions; import jaxx.runtime.spi.UIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.widgets.gis.CoordinateComponentPositions; import org.nuiton.jaxx.widgets.gis.DmdCoordinate; import org.nuiton.jaxx.widgets.gis.DmdCoordinateConverter; import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; +import org.nuiton.jaxx.widgets.jformattedtextfield.JFormattedTextFieldNavigationManager; import org.nuiton.util.beans.BeanUtil; import javax.swing.JFormattedTextField; @@ -118,8 +118,7 @@ public class AbsoluteDmdCoordinateEditorHandler implements UIHandler<AbsoluteDmd JFormattedTextField editor = ui.getEditor(); - CoordinateComponentPositions componentPositions = CoordinateComponentPositions.create(pattern.replaceAll("''","'")); - componentPositions.installKeyListener(editor); + JFormattedTextFieldNavigationManager.install(pattern.replaceAll("''", "'"), editor); DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(maskFormatter); editor.setFormatterFactory(formatterFactory); diff --git a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java index d12a214..19403e6 100644 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java @@ -26,9 +26,9 @@ import com.google.common.base.Preconditions; import jaxx.runtime.spi.UIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.widgets.gis.CoordinateComponentPositions; import org.nuiton.jaxx.widgets.gis.DmsCoordinate; import org.nuiton.jaxx.widgets.gis.DmsCoordinateConverter; +import org.nuiton.jaxx.widgets.jformattedtextfield.JFormattedTextFieldNavigationManager; import org.nuiton.jaxx.widgets.gis.MaskFormatterFromConverter; import org.nuiton.util.beans.BeanUtil; @@ -116,8 +116,7 @@ public class AbsoluteDmsCoordinateEditorHandler implements UIHandler<AbsoluteDms JFormattedTextField editor = ui.getEditor(); - CoordinateComponentPositions componentPositions = CoordinateComponentPositions.create(pattern.replaceAll("''","'")); - componentPositions.installKeyListener(editor); + JFormattedTextFieldNavigationManager.install(pattern.replaceAll("''", "'"), editor); DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(maskFormatter); editor.setFormatterFactory(formatterFactory); diff --git a/jaxx-widgets-gis/src/test/resources/log4j.properties b/jaxx-widgets-gis/src/test/resources/log4j.properties index 40e5308..5438660 100644 --- a/jaxx-widgets-gis/src/test/resources/log4j.properties +++ b/jaxx-widgets-gis/src/test/resources/log4j.properties @@ -27,6 +27,6 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n log4j.logger.jaxx.runtime.swing=DEBUG -log4j.logger.org.nuiton.jaxx.widgets.gis=DEBUG +log4j.logger.org.nuiton.jaxx.widgets.jformattedtextfield=DEBUG #log4j.logger.jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder=DEBUG log4j.logger.org.nuiton=WARN -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jaxx. See http://git.nuiton.org/jaxx.git commit c63b6756d47a140dc9abfa94dcdce4005fff75c6 Merge: 50c8c53 74be8e0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Mar 21 11:44:13 2015 +0100 fixes #3656: Introduce a API to navigate inside a JFormattedTextField using a mask fixes #3655: [AbsoluteCoordinateEditor] Improve navigation of a coordinate Merge branch 'feature/3655' into develop why this merge is necessary, .../JFormattedTextFieldNavigationManager.java | 346 +++++++++++++++++++++ .../JFormatterTextFieldInternalGroup.java | 92 ++++++ .../JFormatterTextFieldInternalGroups.java | 130 ++++++++ jaxx-widgets-gis/pom.xml | 6 + .../gis/absolute/AbsoluteDdCoordinateEditor.jaxx | 4 +- .../AbsoluteDdCoordinateEditorHandler.java | 3 + .../AbsoluteDmdCoordinateEditorHandler.java | 3 + .../AbsoluteDmsCoordinateEditorHandler.java | 3 + .../absolute/AbsoluteDdCoordinateEditorTest.java | 116 +++++++ .../absolute/AbsoluteDmsCoordinateEditorTest.java | 125 ++++++++ .../src/test/resources/log4j.properties | 1 + 11 files changed, 827 insertions(+), 2 deletions(-) diff --cc jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java index 0000000,e563722..3c65fb2 mode 000000,100644..100644 --- a/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java +++ b/jaxx-widgets-common/src/main/java/org/nuiton/jaxx/widgets/jformattedtextfield/JFormattedTextFieldNavigationManager.java @@@ -1,0 -1,337 +1,346 @@@ + package org.nuiton.jaxx.widgets.jformattedtextfield; + ++import com.google.common.base.Preconditions; + import org.apache.commons.logging.Log; + import org.apache.commons.logging.LogFactory; + + import javax.swing.JFormattedTextField; + import javax.swing.SwingUtilities; ++import javax.swing.text.MaskFormatter; + import java.awt.event.FocusAdapter; + import java.awt.event.FocusEvent; + import java.awt.event.KeyAdapter; + import java.awt.event.KeyEvent; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseEvent; + import java.util.HashMap; + import java.util.Map; + + /** + * Manager to navigate inside a JFormattedTextField using a MaskFormatter. + * + * Created on 3/21/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 2.23 + */ + public class JFormattedTextFieldNavigationManager { + + /** Logger. */ + private static final Log log = LogFactory.getLog(JFormattedTextFieldNavigationManager.class); + + private static final String CLIENT_PROPERTY_NAVIGATION_MANAGER = "JFormattedTextFieldNavigationHandler"; + - public static void install(String pattern, JFormattedTextField component) { ++ public static void install(JFormattedTextField component) { + - JFormatterTextFieldInternalGroups componentPositions = JFormatterTextFieldInternalGroups.create(pattern); ++ JFormattedTextField.AbstractFormatter formatter = component.getFormatter(); ++ ++ Preconditions.checkState(formatter != null, "No formatter found on " + component); ++ Preconditions.checkState(formatter instanceof MaskFormatter, "Formatter " + formatter + " is not a MaskFormatter"); ++ ++ String mask = ((MaskFormatter) formatter).getMask(); ++ ++ JFormatterTextFieldInternalGroups componentPositions = JFormatterTextFieldInternalGroups.create(mask); + + JFormattedTextFieldNavigationManager handler = new JFormattedTextFieldNavigationManager(componentPositions, component); + component.putClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER, handler); + handler.install0(component); + + } + + public static void uninstall(JFormattedTextField component) { + + JFormattedTextFieldNavigationManager handler = (JFormattedTextFieldNavigationManager) component.getClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER); + try { + handler.uninstall0(component); + } finally { + component.putClientProperty(CLIENT_PROPERTY_NAVIGATION_MANAGER, null); + } + + } + + private final JFormatterTextFieldInternalGroups groups; + + private final KeyAdapter keyAdapter; + + private final MouseAdapter mouseAdapter; + + private final FocusAdapter focusAdapter; + + private final Map<JFormatterTextFieldInternalGroup, SelectComponentAction> actions; + + private JFormatterTextFieldInternalGroup lastGroup = null; + + protected JFormattedTextFieldNavigationManager(JFormatterTextFieldInternalGroups groups, JFormattedTextField component) { + + this.groups = groups; + + this.actions = new HashMap<JFormatterTextFieldInternalGroup, SelectComponentAction>(); + for (JFormatterTextFieldInternalGroup componentPosition : groups) { + actions.put(componentPosition, new SelectComponentAction(component, componentPosition)); + } + + this.keyAdapter = new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + int caretPosition = source.getCaretPosition(); + + if (canGoRight(e)) { + + goRight(source, caretPosition); + e.consume(); + + } else if (canTransferFocus(e)) { + + source.transferFocus(); + e.consume(); + + } else if (canGoLeft(e)) { + + goLeft(source, caretPosition); + e.consume(); + + } else if (canTransferFocusBackward(e)) { + + source.transferFocusBackward(); + e.consume(); + + } + + } + + @Override + public void keyReleased(KeyEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + + }; + + this.mouseAdapter = new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + }; + + this.focusAdapter = new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + + lastGroup = null; + + JFormattedTextField source = (JFormattedTextField) e.getSource(); + JFormatterTextFieldInternalGroup currentGroup = getCurrentGroup(source); + selectComponent(currentGroup); + + } + }; + + } + + protected void gotoComponent(JFormattedTextField source, JFormatterTextFieldInternalGroup group) { + + if (group != null) { + + int startIndex = group.getStartIndex(); + int endIndex = group.getEndIndex(); + if (log.isDebugEnabled()) { + log.debug(String.format("Goto component [%s - %s]", startIndex, endIndex)); + } + source.setCaretPosition(startIndex); + + } + + } + + protected void selectComponent(JFormatterTextFieldInternalGroup currentGroup) { + + if (lastGroup == null || !lastGroup.equals(currentGroup)) { + + if (log.isDebugEnabled()) { + log.debug("New select group: " + currentGroup); + } + lastGroup = currentGroup; + + SelectComponentAction action = actions.get(currentGroup); + SwingUtilities.invokeLater(action); + + } + + } + + protected JFormatterTextFieldInternalGroup getCurrentGroup(JFormattedTextField source) { + + int caretPosition = source.getCaretPosition(); + return groups.getGroupAtPosition(caretPosition); + + } + + protected void goRight(JFormattedTextField source, int caretPosition) { + + if (lastGroup == null || !lastGroup.isLastGroup()) { + + if (log.isDebugEnabled()) { + log.debug("Go right from position " + caretPosition); + } + JFormatterTextFieldInternalGroup currentGroup = groups.getGroupAtPosition(caretPosition); + JFormatterTextFieldInternalGroup nextGroup = currentGroup.getNextGroup(); + gotoComponent(source, nextGroup); + + } + + } + + protected void goLeft(JFormattedTextField source, int caretPosition) { + + if (lastGroup == null || !lastGroup.isFirstGroup()) { + + if (log.isDebugEnabled()) { + log.debug("Go left from position " + caretPosition); + } + JFormatterTextFieldInternalGroup currentGroup = groups.getGroupAtPosition(caretPosition); + JFormatterTextFieldInternalGroup nextGroup = currentGroup.getPreviousGroup(); + gotoComponent(source, nextGroup); + + } + } + + + protected boolean canGoRight(KeyEvent e) { + + boolean result = false; + + boolean noModifiers = e.getModifiers() == 0; + + if (KeyEvent.VK_RIGHT == e.getKeyCode() && noModifiers) { + + // right key go to next component + result = true; + + } else if (KeyEvent.VK_TAB == e.getKeyCode() && noModifiers) { + + // Tab go to next component if not on last one + result = lastGroup == null || !lastGroup.isLastGroup(); + + } + + return result; + + } + + protected boolean canGoLeft(KeyEvent e) { + + boolean result = false; + + if (KeyEvent.VK_LEFT == e.getKeyCode() && e.getModifiers() == 0) { + + // Left key go to previous component + result = true; + + } else if (KeyEvent.VK_TAB == e.getKeyCode() && e.isShiftDown() && !e.isControlDown()) { + + // Shift Tab go to previous component if not on first one + result = lastGroup != null && !lastGroup.isFirstGroup(); + + } + + return result; + + } + + protected boolean canTransferFocus(KeyEvent e) { + + boolean result = false; + + boolean onTabKey = KeyEvent.VK_TAB == e.getKeyCode(); + + if (onTabKey && e.isControlDown() && !e.isShiftDown()) { + + // Ctrl Tab go direct to focus + result = true; + + } else if (onTabKey && e.getModifiers() == 0) { + + // Tab on last component go to focus + result = lastGroup != null && lastGroup.isLastGroup(); + + } + + return result; + + } + + protected boolean canTransferFocusBackward(KeyEvent e) { + + boolean result = false; + + boolean onShiftTabKey = KeyEvent.VK_TAB == e.getKeyCode() && e.isShiftDown(); + + if (onShiftTabKey && e.isControlDown()) { + + // Ctrl Shift Tab go direct to focus backward + result = true; + + } else if (onShiftTabKey) { + + // Shit Tab go to focus backward only if no component selected or on the first one + result = lastGroup == null || lastGroup.isFirstGroup(); + + } + + return result; + + } + + private void install0(JFormattedTextField component) { + + component.setFocusTraversalKeysEnabled(false); + component.addKeyListener(keyAdapter); + component.addMouseListener(mouseAdapter); + component.addFocusListener(focusAdapter); + } + + private void uninstall0(JFormattedTextField component) { + + component.setFocusTraversalKeysEnabled(true); + component.removeKeyListener(keyAdapter); + component.removeMouseListener(mouseAdapter); + component.removeFocusListener(focusAdapter); + + } + + private static class SelectComponentAction implements Runnable { + + private final JFormatterTextFieldInternalGroup group; + + private final JFormattedTextField source; + + private SelectComponentAction(JFormattedTextField source, JFormatterTextFieldInternalGroup group) { + this.group = group; + this.source = source; + } + + @Override + public void run() { + + int startIndex = group.getStartIndex(); + int endIndex = group.getEndIndex() + 1; + if (log.isDebugEnabled()) { + log.debug(String.format("Select group [%s]", group)); + } + source.select(startIndex, endIndex); + + } + } + + } diff --cc jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java index b4f408a,322c856..8765bb7 --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDdCoordinateEditorHandler.java @@@ -125,6 -128,6 +126,8 @@@ public class AbsoluteDdCoordinateEditor } }); ++ JFormattedTextFieldNavigationManager.install(editor); ++ // When model degree changed, let's push it back in bean model.addPropertyChangeListener( AbsoluteDdCoordinateEditorModel.PROPERTY_DEGREE, diff --cc jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java index e42e078,ccd9af0..250c64d --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmdCoordinateEditorHandler.java @@@ -133,6 -136,6 +134,8 @@@ public class AbsoluteDmdCoordinateEdito } }); ++ JFormattedTextFieldNavigationManager.install(editor); ++ // When model degre changed, let's push it back in bean model.addPropertyChangeListener( AbsoluteDmdCoordinateEditorModel.PROPERTY_DEGREE, diff --cc jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java index 69060ee,19403e6..991d4be --- a/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java +++ b/jaxx-widgets-gis/src/main/java/org/nuiton/jaxx/widgets/gis/absolute/AbsoluteDmsCoordinateEditorHandler.java @@@ -131,6 -134,6 +132,8 @@@ public class AbsoluteDmsCoordinateEdito } }); ++ JFormattedTextFieldNavigationManager.install(editor); ++ // When model degre changed, let's push it back in bean model.addPropertyChangeListener( AbsoluteDmsCoordinateEditorModel.PROPERTY_DEGREE, -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm