📄 scenariographicloader.java
字号:
// } catch (MalformedURLException murle) { // Debug.error("ScenarioGraphicLoader " + getName() + ":" + // murle.getMessage()); // } catch (NullPointerException npe) { // Debug.error("ScenarioGraphicLoader " + getName() + ":" + // npe.getMessage()); // } // timerControl = new TimerControlButtonPanel(this); // jtb.add(timerControl); // pcs.addPropertyChangeListener(TIMER_RUNNING_STATUS, // timerControl); // String runningStatus = timer.isRunning()?(getClockDirection() > // 0?TIMER_FORWARD:TIMER_BACKWARD):TIMER_STOPPED; // pcs.firePropertyChange(TIMER_RUNNING_STATUS, null, // runningStatus); // timerRateControl = new TimerRateComboBox(this); // timerRateControl.setToolTipText("Change clock rate for // Scenario"); // Iterator it = timerRates.iterator(); // while (it.hasNext()) { // TimerRateHolder trh = (TimerRateHolder)it.next(); // timerRateControl.add(trh.label, trh.clock, trh.pace); // } // int si = timerRates.size()/2; // if (si > 0) { // timerRateControl.setSelectedIndex(si); // } // jtb.add(timerRateControl); // timeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0); // timeSliderSupport = new TimeSliderSupport(timeSlider, this, // startTime, endTime); // jtb.add(timeSlider); // timeLabel = new JLabel(); // java.awt.Font defaultFont = timeLabel.getFont(); // timeLabel.setFont(new java.awt.Font(defaultFont.getName(), // defaultFont.getStyle(), 9)); // jtb.add(timeLabel); // return jtb; // } /** * Tool Method. The retrieval tool's interface. This is added to * the tool bar. * * @return String The key for this tool. */ public Container getFace() { JPanel jtb = new JPanel(); Box bigBox = Box.createHorizontalBox(); Box rightBox = Box.createVerticalBox(); Box leftBox = Box.createVerticalBox(); Box innerBox = Box.createHorizontalBox(); try { URL url = PropUtils.getResourceOrFileOrURL(this, snapshotIconName); ImageIcon snapshotIcon = new ImageIcon(url); url = PropUtils.getResourceOrFileOrURL(this, totalScenarioIconName); ImageIcon totalScenarioIcon = new ImageIcon(url); timeWrapToggle = new JToggleButton(totalScenarioIcon, timeWrap); timeWrapToggle.setSelectedIcon(snapshotIcon); timeWrapToggle.setActionCommand(SCENARIO_MODE_CMD); timeWrapToggle.addActionListener(this); timeWrapToggle.setToolTipText("Wrap Scenario Time Scale"); // jtb.add(timeWrapToggle); innerBox.add(timeWrapToggle); } catch (MalformedURLException murle) { Debug.error("ScenarioGraphicLoader " + getName() + ":" + murle.getMessage()); } catch (NullPointerException npe) { Debug.error("ScenarioGraphicLoader " + getName() + ":" + npe.getMessage()); } timerControl = new TimerControlButtonPanel(this); // jtb.add(timerControl); innerBox.add(timerControl); rightBox.add(innerBox); pcs.addPropertyChangeListener(TIMER_RUNNING_STATUS, timerControl); String runningStatus = timer.isRunning() ? (getClockDirection() > 0 ? TIMER_FORWARD : TIMER_BACKWARD) : TIMER_STOPPED; pcs.firePropertyChange(TIMER_RUNNING_STATUS, null, runningStatus); timerRateControl = new TimerRateComboBox(this); timerRateControl.setToolTipText("Change clock rate for Scenario"); Iterator it = timerRates.iterator(); while (it.hasNext()) { TimerRateHolder trh = (TimerRateHolder) it.next(); timerRateControl.add(trh.label, trh.clock, trh.pace); } int si = timerRates.size() / 2; if (si > 0) { timerRateControl.setSelectedIndex(si); } // jtb.add(timerRateControl); rightBox.add(timerRateControl); timeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 0); timeSliderSupport = new TimeSliderSupport(timeSlider, this, startTime, endTime); // jtb.add(timeSlider); leftBox.add(timeSlider); timeLabel = new JLabel(" ", SwingConstants.CENTER); java.awt.Font defaultFont = timeLabel.getFont(); timeLabel.setFont(new java.awt.Font(defaultFont.getName(), defaultFont.getStyle(), 10)); // jtb.add(timeLabel); leftBox.add(timeLabel); URL url = ScenarioGraphicLoader.class.getResource("path.png"); ImageIcon icon = new ImageIcon(url); JToggleButton modeButton = new JToggleButton(icon, mode == TOTAL_SCENARIO_MODE); modeButton.setToolTipText((mode == TOTAL_SCENARIO_MODE ? "Hide" : "Show") + " scenario paths on " + getName()); modeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JToggleButton jtb = (JToggleButton) ae.getSource(); boolean sel = jtb.isSelected(); setMode((sel ? TOTAL_SCENARIO_MODE : SNAPSHOT_SCENARIO_MODE)); jtb.setToolTipText((sel ? "Hide" : "Show") + " scenario paths on " + getName()); manageGraphics(); } }); bigBox.add(modeButton); bigBox.add(leftBox); bigBox.add(rightBox); jtb.add(bigBox); return jtb; } public String getMode() { return mode; } public void setMode(String mode) { this.mode = mode; } /** * Tool Method. The retrieval key for this tool. * * @return String The key for this tool. */ public String getKey() { return getName(); } /** * Tool Method. Set the retrieval key for this tool. * * @param aKey The key for this tool. */ public void setKey(String aKey) { setName(aKey); } /** * DataBoundsProvider method. */ public DataBounds getDataBounds() { return dataBounds; } public void componentResized(ComponentEvent ce) {} public void componentMoved(ComponentEvent ce) {} public void componentHidden(ComponentEvent ce) {} public void componentShown(ComponentEvent ce) {} /** * An OMGraphicList that knows what a ScenarioGraphic is, and * knows when to tell it to draw itself at a particular time, or * if it should draw its entire scenario path. */ public class ScenarioGraphicList extends OMGraphicList { public ScenarioGraphicList() { super(); } public void generate(Projection p, long time, boolean showScenario) { synchronized (graphics) { Iterator it = iterator(); while (it.hasNext()) { OMGraphic graphic = (OMGraphic) it.next(); if (graphic instanceof ScenarioGraphic) { ((ScenarioGraphic) graphic).generate(p, time, showScenario); } else { graphic.generate(p); } } } } } /** * A convenience class that keeps track of a relationship between * real-time changes and scenario-time changes. */ public class TimerRateHolder implements PropertyConsumer { String label; int clock; int pace; SimpleDateFormat paceFormat; String paceZero; boolean valid = false; String propPrefix; /** * Create a TimerRateHolder with a date format, and a baseline * time. The default baseline time is "00:00:00", so if you * need to change that, use this constructor. The pace for * this TimerRateHolder should be a relative amount of time, * and that relativity, taking into account the locale offset * to GMT, is given by the baseline time. The baseline time * should match the format given. */ public TimerRateHolder(SimpleDateFormat simpleDateFormat, String dpz) { paceFormat = simpleDateFormat; paceZero = dpz; } public String toString() { return "ScenarioGraphicLoader.TimerRateHolder [" + label + ", clock:" + clock + ", pace:" + pace + "] (" + valid + ")"; } public void setProperties(Properties props) { setProperties(null, props); } public void setProperties(String prefix, Properties props) { propPrefix = prefix; prefix = PropUtils.getScopedPropertyPrefix(prefix); try { label = props.getProperty(prefix + Layer.PrettyNameProperty); clock = PropUtils.intFromProperties(props, prefix + ClockIntervalProperty, -1); String paceString = props.getProperty(prefix + PaceProperty); pace = (int) (paceFormat.parse(paceString).getTime() - paceFormat.parse(paceZero) .getTime()); valid = true; } catch (NullPointerException npe) { Debug.error("TimerRateHolder caught NPE: " + npe.getMessage()); } catch (ParseException pe) { Debug.error("TimerRateHolder parse exception: " + pe.getMessage()); } } public Properties getProperties(Properties props) { return props; } public Properties getPropertyInfo(Properties props) { return props; } public String getPropertyPrefix() { return propPrefix; } public void setPropertyPrefix(String p) { propPrefix = p; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -