Changeset 2044


Ignore:
Timestamp:
10/20/15 10:13:39 (9 years ago)
Author:
pharms
Message:
  • added correct handling of views and GUI element distance calculation
Location:
trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/guimodel
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/guimodel/JFCDialog.java

    r1876 r2044  
    1616 
    1717import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame; 
    18 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; 
    1918 
    2019/** 
     
    2625 * @author Patrick Harms 
    2726 */ 
    28 public class JFCDialog extends JFCGUIElement implements IFrame, IGUIView { 
     27public class JFCDialog extends JFCGUIElement implements IFrame { 
    2928 
    3029    /** 
     
    6059    } 
    6160 
    62     /* (non-Javadoc) 
    63      * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView#isModal() 
    64      */ 
    65     @Override 
    66     public boolean isModal() { 
    67         return true; 
    68     } 
    69  
    7061} 
  • trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/guimodel/JFCFrame.java

    r1876 r2044  
    1616 
    1717import de.ugoe.cs.autoquest.eventcore.guimodel.IFrame; 
    18 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; 
    1918 
    2019/** 
     
    2625 * @author Patrick Harms 
    2726 */ 
    28 public class JFCFrame extends JFCGUIElement implements IFrame, IGUIView { 
     27public class JFCFrame extends JFCGUIElement implements IFrame { 
    2928 
    3029    /** 
     
    6059    } 
    6160 
    62     /* (non-Javadoc) 
    63      * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView#isModal() 
    64      */ 
    65     @Override 
    66     public boolean isModal() { 
    67         return false; 
    68     } 
    69  
    7061} 
  • trunk/autoquest-plugin-jfc/src/main/java/de/ugoe/cs/autoquest/plugin/jfc/guimodel/JFCGUIElement.java

    r1876 r2044  
    3939    /** 
    4040     * <p> 
     41     * the default distance value for different applications 
     42     * </p> 
     43     */ 
     44    protected static final double DISTANCE_DISTINCT_APPLICATION = 1.0; 
     45 
     46    /** 
     47     * <p> 
     48     * the default distance value for same application but different views, i.e., dialogs, frames, 
     49     * or tabbed panes 
     50     * </p> 
     51     */ 
     52    protected static final double DISTANCE_SAME_APPLICATION = 0.75; 
     53 
     54    /** 
     55     * <p> 
     56     * the default distance value for same view but different panels 
     57     * </p> 
     58     */ 
     59    protected static final double DISTANCE_SAME_VIEW = 0.5; 
     60 
     61    /** 
     62     * <p> 
     63     * the default distance value for same parent panel but different GUI elements  
     64     * </p> 
     65     */ 
     66    protected static final double DISTANCE_SAME_PANEL = 0.2; 
     67 
     68    /** 
     69     * <p> 
     70     * the default distance value for identical GUI elements 
     71     * </p> 
     72     */ 
     73    protected static final double DISTANCE_NONE = 0.0; 
     74 
     75    /** 
     76     * <p> 
    4177     * Specification of the GUI Element 
    4278     * </p> 
     
    192228    @Override 
    193229    public IGUIView getView() { 
    194         IGUIElement element = this; 
    195          
    196         while ((element != null) && (!(element instanceof IGUIView))) { 
     230        JFCGUIElement element = this; 
     231         
     232        while ((element != null) && (!(element instanceof JFCFrame)) && 
     233               (!(element instanceof JFCDialog))) 
     234        { 
    197235            if (!(element.getParent() instanceof JFCTabbedPane)) { 
    198                 element = element.getParent(); 
     236                element = (JFCGUIElement) element.getParent(); 
    199237            } 
    200238            else { 
     
    204242        } 
    205243         
    206         return (IGUIView) element; 
     244        return new JFCView(element); 
    207245    } 
    208246 
     
    214252    @Override 
    215253    public double getDistanceTo(IGUIElement otherElement) { 
    216         throw new UnsupportedOperationException("not implemented yet"); 
     254        if (otherElement instanceof JFCGUIElement) { 
     255            if (equals(otherElement)) { 
     256                return DISTANCE_NONE; 
     257            } 
     258             
     259            if (!areInSameView(this, otherElement)) { 
     260                IGUIElement root1 = this; 
     261                 
     262                while (root1.getParent() != null) { 
     263                    root1 = root1.getParent(); 
     264                } 
     265                 
     266                IGUIElement root2 = otherElement; 
     267                 
     268                while (root2.getParent() != null) { 
     269                    root2 = root2.getParent(); 
     270                } 
     271                 
     272                if (!root1.equals(root2)) { 
     273                    return DISTANCE_DISTINCT_APPLICATION; 
     274                } 
     275                else { 
     276                    return DISTANCE_SAME_APPLICATION; 
     277                } 
     278            } 
     279            else { 
     280                // check if they have the same parent panel. If so, they are very close. 
     281                // If not, they may be structured completely differently 
     282                IGUIElement parentPanel1 = this; 
     283                 
     284                while (parentPanel1 != null) { 
     285                    if ((parentPanel1 instanceof JFCPanel) || 
     286                        (parentPanel1 instanceof JFCFrame) || 
     287                        (parentPanel1 instanceof JFCDialog) || 
     288                        (parentPanel1 instanceof JFCCanvas) || 
     289                        (parentPanel1 instanceof JFCMenu) || 
     290                        (parentPanel1 instanceof JFCScrollPane) || 
     291                        (parentPanel1 instanceof JFCSplitPane) || 
     292                        (parentPanel1 instanceof JFCTabbedPane)) 
     293                    { 
     294                        break; 
     295                    } 
     296                    else { 
     297                        parentPanel1 = parentPanel1.getParent(); 
     298                    } 
     299                } 
     300                 
     301                IGUIElement parentPanel2 = otherElement; 
     302                 
     303                while (parentPanel2 != null) { 
     304                    if ((parentPanel2 instanceof JFCPanel) || 
     305                        (parentPanel2 instanceof JFCFrame) || 
     306                        (parentPanel2 instanceof JFCDialog) || 
     307                        (parentPanel2 instanceof JFCCanvas) || 
     308                        (parentPanel2 instanceof JFCMenu) || 
     309                        (parentPanel2 instanceof JFCScrollPane) || 
     310                        (parentPanel2 instanceof JFCSplitPane) || 
     311                        (parentPanel2 instanceof JFCTabbedPane)) 
     312                    { 
     313                        break; 
     314                    } 
     315                    else { 
     316                        parentPanel2 = parentPanel2.getParent(); 
     317                    } 
     318                } 
     319                 
     320                // a check for the identity of the objects is sufficient. That they resist on the 
     321                // same document was checked beforehand. So even a condense of the GUI model should 
     322                // not cause an invalid result here. 
     323                if ((parentPanel1 == parentPanel2) || 
     324                    ((parentPanel1 != null) && (parentPanel1.equals(parentPanel2)))) 
     325                { 
     326                    return DISTANCE_SAME_PANEL; 
     327                } 
     328                else { 
     329                    return DISTANCE_SAME_VIEW; 
     330                } 
     331            } 
     332        } 
     333         
     334        return DISTANCE_DISTINCT_APPLICATION; 
    217335    } 
    218336 
     
    228346    } 
    229347 
     348    /** 
     349     * <p> 
     350     * convenience method to check if two GUI elements are in the same view. In contrast to other 
     351     * technologies, JFC GUI views may have other views as children. Hence, it is not sufficient to 
     352     * check, if the direct parent views are identical. 
     353     * </p> 
     354     */ 
     355    private boolean areInSameView(IGUIElement guiElement1, IGUIElement guiElement2) { 
     356        IGUIView view1 = guiElement1.getView(); 
     357        IGUIElement other = guiElement2; 
     358         
     359        while (other != null) { 
     360            if (view1.equals(other.getView())) { 
     361                return true; 
     362            } 
     363             
     364            other = other.getParent(); 
     365        } 
     366         
     367        // the parent views of the other gui element are checked. But not the ones of this. Hence, 
     368        // check also them. 
     369        if ((view1 instanceof JFCView) && (((JFCView) view1).getParent() != null)) { 
     370            return areInSameView(((JFCView) view1).getParent(), guiElement2); 
     371        } 
     372        else { 
     373            return false; 
     374        } 
     375    } 
    230376} 
Note: See TracChangeset for help on using the changeset viewer.