< prev index next >

src/demo/share/jfc/J2Ddemo/java2d/DemoPanel.java

Print this page


   1 /*
   2  *
   3  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  57     public Tools tools;
  58     public String className;
  59 
  60     public DemoPanel(Object obj, DemoInstVarsAccessor demoInstVars) {
  61         this.demoInstVars = demoInstVars;
  62 
  63         setLayout(new BorderLayout());
  64         try {
  65             if (obj instanceof String) {
  66                 className = (String) obj;
  67                 obj = Class.forName(className).newInstance();
  68             }
  69             if (obj instanceof Component) {
  70                 add((Component) obj);
  71             }
  72             if (obj instanceof Surface) {
  73                 add("South", tools = new Tools(surface = (Surface) obj, demoInstVars));
  74             }
  75             if (obj instanceof CustomControlsContext) {
  76                 ccc = (CustomControlsContext) obj;
  77                 Component cmps[] = ccc.getControls();
  78                 String cons[] = ccc.getConstraints();
  79                 for (int i = 0; i < cmps.length; i++) {
  80                     add(cmps[i], cons[i]);
  81                 }
  82             }
  83         } catch (Exception e) {
  84             Logger.getLogger(DemoPanel.class.getName()).log(Level.SEVERE, null,
  85                     e);
  86         }
  87     }
  88 
  89     public void start() {
  90         if (surface != null) {
  91             surface.startClock();
  92         }
  93         if (tools != null && surface != null) {
  94             if (tools.startStopB != null && tools.startStopB.isSelected()) {
  95                 surface.animating.start();
  96             }
  97         }
  98         if (ccc != null


   1 /*
   2  *
   3  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   4  *
   5  * Redistribution and use in source and binary forms, with or without
   6  * modification, are permitted provided that the following conditions
   7  * are met:
   8  *
   9  *   - Redistributions of source code must retain the above copyright
  10  *     notice, this list of conditions and the following disclaimer.
  11  *
  12  *   - Redistributions in binary form must reproduce the above copyright
  13  *     notice, this list of conditions and the following disclaimer in the
  14  *     documentation and/or other materials provided with the distribution.
  15  *
  16  *   - Neither the name of Oracle nor the names of its
  17  *     contributors may be used to endorse or promote products derived
  18  *     from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


  57     public Tools tools;
  58     public String className;
  59 
  60     public DemoPanel(Object obj, DemoInstVarsAccessor demoInstVars) {
  61         this.demoInstVars = demoInstVars;
  62 
  63         setLayout(new BorderLayout());
  64         try {
  65             if (obj instanceof String) {
  66                 className = (String) obj;
  67                 obj = Class.forName(className).newInstance();
  68             }
  69             if (obj instanceof Component) {
  70                 add((Component) obj);
  71             }
  72             if (obj instanceof Surface) {
  73                 add("South", tools = new Tools(surface = (Surface) obj, demoInstVars));
  74             }
  75             if (obj instanceof CustomControlsContext) {
  76                 ccc = (CustomControlsContext) obj;
  77                 Component[] cmps = ccc.getControls();
  78                 String[] cons = ccc.getConstraints();
  79                 for (int i = 0; i < cmps.length; i++) {
  80                     add(cmps[i], cons[i]);
  81                 }
  82             }
  83         } catch (Exception e) {
  84             Logger.getLogger(DemoPanel.class.getName()).log(Level.SEVERE, null,
  85                     e);
  86         }
  87     }
  88 
  89     public void start() {
  90         if (surface != null) {
  91             surface.startClock();
  92         }
  93         if (tools != null && surface != null) {
  94             if (tools.startStopB != null && tools.startStopB.isSelected()) {
  95                 surface.animating.start();
  96             }
  97         }
  98         if (ccc != null


< prev index next >