Changeset 86 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/gui


Ignore:
Timestamp:
08/27/2017 02:58:02 PM (9 years ago)
Author:
jdalbey
Message:

Add new file OverviewWinSpike?.java to experiment with Overview Window layout.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/gui/panels/OverviewWinSpike.java

    r76 r86  
    22 
    33import java.awt.BorderLayout; 
    4 import java.awt.Dimension; 
    5 import java.awt.Graphics; 
    6 import java.awt.Graphics2D; 
    7 import java.awt.event.MouseEvent; 
    84import java.io.File; 
     5import javax.swing.BoxLayout; 
    96import javax.swing.JFrame; 
    107import javax.swing.JPanel; 
    11 import javax.swing.event.MouseInputAdapter; 
    12 import static junit.framework.Assert.assertEquals; 
    13 import scriptbuilder.gui.IncidentEditorFrame; 
    14 import scriptbuilder.gui.ScriptBuilderFrame; 
    15 import scriptbuilder.gui.ScriptBuilderGuiConstants; 
    16 import scriptbuilder.gui.drawers.EventIconDrawer; 
     8import scriptbuilder.gui.drawers.RangeSlider; 
    179import scriptbuilder.structures.ScriptIncident; 
    1810import scriptbuilder.structures.SimulationScript; 
    1911 
    2012/** 
    21  * Represents the underlying panel on the main timeline. All the 
    22  * IncidentTimelinePanel objects sit over it. This panel draws all the 
    23  * per-minute ticks on the timeline, and adjusts and scales them as necessary. 
    24  * 
    25  * @author Greg Eddington <geddingt@calpoly.edu> 
    26  * @author Bryan McGuffin 
     13 * Exploration (spike) for Overview Window. 
     14 * The background is a TimelineTickPanel. 
     15 * IncidentTimelinePanel objects sit over it.  
     16 * @author jdalbey 
    2717 */ 
    28 public class TimelineTickPanel extends JPanel 
     18public class OverviewWinSpike  
    2919{ 
    30  
    31     private int longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH; 
    32     private int x, y; 
    33     private boolean focused = false; 
    34  
    35 //    public void setZoom(float zoom) 
    36 //    { 
    37 //        repaint(); 
    38 //    } 
    39     /** 
    40      * Listener for the mouse. Is notified when the mouse enters, exits, or 
    41      * moves around on the panel. 
    42      */ 
    43     public class TimelineTickMouseListener extends MouseInputAdapter 
    44     { 
    45  
    46         /** 
    47          * When the mouse enters the panel, the panel gets focus. 
    48          * 
    49          * @param e the mouse event 
    50          */ 
    51         @Override 
    52         public void mouseEntered(MouseEvent e) 
    53         { 
    54             focused = true; 
    55         } 
    56  
    57         /** 
    58          * When the mouse leaves the panel, the panel loses focus and refreshes. 
    59          * 
    60          * @param e the mouse event 
    61          */ 
    62         @Override 
    63         public void mouseExited(MouseEvent e) 
    64         { 
    65             focused = false; 
    66             repaint(); 
    67         } 
    68  
    69         /** 
    70          * When the mouse moves around in the panel, the panel refreshes and 
    71          * updates its mouse tracker. 
    72          * 
    73          * @param e 
    74          */ 
    75         @Override 
    76         public void mouseMoved(MouseEvent e) 
    77         { 
    78             x = e.getX(); 
    79             y = e.getY(); 
    80  
    81             repaint(); 
    82         } 
    83     } 
    84  
    85     /** 
    86      * Constructor. Set up the mouse listener. 
    87      */ 
    88     public TimelineTickPanel() 
    89     { 
    90         super(); 
    91  
    92         TimelineTickMouseListener mouseListener 
    93                 = new TimelineTickMouseListener(); 
    94         addMouseMotionListener(mouseListener); 
    95         addMouseListener(mouseListener); 
    96     } 
    97  
    98     /** 
    99      * Update the panel's dimensions based on number of events, zoom level, and 
    100      * which events are collapsed. The version of the method is used in the main 
    101      * script builder. 
    102      * 
    103      * @param script The main script model 
    104      */ 
    105     public void update(SimulationScript script) 
    106     { 
    107         longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH; 
    108  
    109         // Get the stats on the incidents 
    110         int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4; 
    111         for (ScriptIncident incident : script.incidents) 
    112         { 
    113             if (incident != null) 
    114             { 
    115                 height += incident.collapsed 
    116                         ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT 
    117                         : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT; 
    118                 if ((incident.length + incident.offset) > longestLength) 
    119                 { 
    120                     longestLength = incident.length + incident.offset; 
    121                 } 
    122             } 
    123         } 
    124  
    125         Dimension newSize = new Dimension(longestLength 
    126                 / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION 
    127                 * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    128                 + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50, 
    129                 height); 
    130         this.setPreferredSize(newSize); 
    131         this.setSize(newSize); 
    132  
    133         this.invalidate(); 
    134     } 
    135  
    136     /** 
    137      * Update the panel's dimensions based on number of events, zoom level, and 
    138      * which events are collapsed. This version of the method is used in the 
    139      * individual incident editor. 
    140      * 
    141      * @param incident the incident being edited 
    142      */ 
    143     public void update(ScriptIncident incident) 
    144     { 
    145         longestLength = ScriptBuilderGuiConstants.TICK_TIMELINE_SMALLEST_LENGTH; 
    146  
    147         // Get the stats on the incidents 
    148         int height = ScriptBuilderGuiConstants.TICK_TOP_MARGIN * 4; 
    149  
    150         if (incident != null) 
    151         { 
    152             height += incident.collapsed 
    153                     ? ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT 
    154                     : ScriptBuilderGuiConstants.TIMELINE_OPENED_HEIGHT; 
    155             if ((incident.length + incident.offset) > longestLength) 
    156             { 
    157                 longestLength = incident.length + incident.offset; 
    158             } 
    159  
    160         } 
    161  
    162         Dimension newSize = new Dimension(longestLength 
    163                 / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION 
    164                 * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    165                 + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN + 50, 
    166                 height); 
    167         this.setPreferredSize(newSize); 
    168         this.setSize(newSize); 
    169  
    170         this.invalidate(); 
    171     } 
    172  
    173     /** 
    174      * Refresh the panel. Redraw the ticks based on zoom level, panel 
    175      * dimensions, and offset. If the user is trying to add an event, draw that 
    176      * event's icon under the mouse. 
    177      * 
    178      * @param g The graphics component 
    179      */ 
    180     @Override 
    181     public void paint(Graphics g) 
    182     { 
    183         super.paint(g); 
    184  
    185         Graphics2D g2d = (Graphics2D) g; 
    186  
    187         // Draw the horizontal line 
    188         g2d.setFont(ScriptBuilderGuiConstants.TIMELINE_TICK_TIME_FONT); 
    189         g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR); 
    190         g2d.fillRect(0, ScriptBuilderGuiConstants.TICK_TIMELINE_TOP_MARGIN, 
    191                 longestLength, ScriptBuilderGuiConstants.TICK_TIMELINE_HEIGHT); 
    192  
    193         // Draw the ticks 
    194         int longestLengthPlusMargin = longestLength 
    195                 / ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION 
    196                 * ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    197                 + ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN; 
    198  
    199         // Minutes 
    200         g2d.setColor(ScriptBuilderGuiConstants.MINOR_TICK_COLOR); 
    201         int seconds = 0; 
    202         for (int i = ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN; 
    203                 i <= longestLengthPlusMargin; 
    204                 i += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK, seconds += ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION) 
    205         { 
    206             g2d.drawLine(i, ScriptBuilderGuiConstants.TICK_TOP_MARGIN, 
    207                     i, ScriptBuilderGuiConstants.TICK_HEIGHT); 
    208         } 
    209  
    210         // Major Ticks 
    211         g2d.setColor(ScriptBuilderGuiConstants.TIMELINE_TICK_COLOR); 
    212         seconds = 0; 
    213         for (int i = ScriptBuilderGuiConstants.TICK_TIMELINE_LEFT_MARGIN; 
    214                 i <= longestLengthPlusMargin; 
    215                 i += ScriptBuilderGuiConstants.PIXEL_WIDTH_PER_HORIZONTAL_TICK 
    216                 * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK, seconds += ScriptBuilderGuiConstants.HORIZONTAL_TICK_RESOLUTION 
    217                 * ScriptBuilderGuiConstants.TICKS_PER_MAJOR_TICK) 
    218         { 
    219             g2d.drawLine(i, ScriptBuilderGuiConstants.TICK_TOP_MARGIN, 
    220                     i, ScriptBuilderGuiConstants.TICK_HEIGHT); 
    221  
    222         } 
    223  
    224         paintChildren(g); 
    225  
    226         if (this.getTopLevelAncestor() instanceof ScriptBuilderFrame) 
    227         { 
    228             if (focused 
    229                     && ((ScriptBuilderFrame) this.getTopLevelAncestor()).currentEventType != null) 
    230             { 
    231                 EventIconDrawer.DrawEventIcon(g2d, 
    232                         ((ScriptBuilderFrame) this.getTopLevelAncestor()).currentEventType, 
    233                         x, y); 
    234             } 
    235         } 
    236         if (this.getTopLevelAncestor() instanceof IncidentEditorFrame) 
    237         { 
    238             if (focused 
    239                     && ((IncidentEditorFrame) this.getTopLevelAncestor()).currentEventType != null) 
    240             { 
    241                 EventIconDrawer.DrawEventIcon(g2d, 
    242                         ((IncidentEditorFrame) this.getTopLevelAncestor()).currentEventType, 
    243                         x, y); 
    244             } 
    245         } 
    246     } 
    247  
    24820    /** 
    24921     * Local main for viewing this panel only. 
     
    25426    public static void main(String[] args) 
    25527    { 
    256         JFrame frame = new JFrame("FrameDemo"); 
     28        JFrame frame = new JFrame("Overview Window Spike"); 
    25729 
    25830        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    25931 
    26032        TimelineTickPanel pnl = new TimelineTickPanel(); 
     33        pnl.setLayout(new BoxLayout(pnl, BoxLayout.PAGE_AXIS)); 
    26134        // Create a script 
    26235        File inFile = new File("test/scriptbuilder/structures/test_input_file.xml"); 
    263         SimulationScript instance = new SimulationScript(); 
    264         instance.loadScriptFromFile(inFile); 
     36        SimulationScript script = new SimulationScript(); 
     37        script.loadScriptFromFile(inFile); 
     38        ScriptIncident incident = script.incidents.get(2); 
     39        IncidentNumberPanel inciNum = new IncidentNumberPanel(); 
     40        inciNum.update(incident); 
     41        JPanel row1 = new JPanel(); 
     42        row1.setOpaque(false);  // so tick lines will show through 
     43        //row1.setSize(200, 500); 
     44        row1.add(inciNum); 
     45        RangeSlider slider = new RangeSlider(0,25); 
     46        slider.setValue(5); 
     47        slider.setUpperValue(10); 
     48        row1.add(slider); 
     49        pnl.add(row1); 
    26550        // update this panel with the script 
    266         pnl.update(instance); 
     51        pnl.update(script); 
    26752        frame.getContentPane().add(pnl, BorderLayout.CENTER); 
    268         frame.setSize(300, 500); 
    26953        frame.pack(); 
    27054 
Note: See TracChangeset for help on using the changeset viewer.