📄 waveformwindow.java
字号:
mouseYOffset = p.y - table.getRowHeight(resizingRow); return; } // forward event to the panel contents forwardEventToPanel(e); } public void mouseMoved(MouseEvent e) { if (getResizingColumn(e.getPoint()) != null) { table.setCursor(resizeColumnCursor); return; } if (getResizingRow(e.getPoint()) >= 0) { table.setCursor(resizeRowCursor); return; } table.setCursor(null); // forward event to the panel contents forwardEventToPanel(e); } public void mouseDragged(MouseEvent e) { if (resizingColumn != null) { resizingColumn.setWidth(e.getX() - mouseXOffset); if (mainHorizRulerPanel != null) mainHorizRulerPanel.repaint(); return; } if (resizingRow >= 0) { int newHeight = e.getY() - mouseYOffset; if (newHeight > 0) { table.setRowHeight(resizingRow, newHeight); return; } } // forward event to the panel contents forwardEventToPanel(e); } public void mouseReleased(MouseEvent e) { if (resizingColumn != null) { table.getTableHeader().setResizingColumn(null); return; } // forward event to the panel contents forwardEventToPanel(e); } public void forwardEventToPanel(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int col = table.columnAtPoint(p); if (row < 0 || col < 0) return; JPanel panel = (JPanel)table.getValueAt(row, col); // so clicks are felt inside the panels MouseEvent panelEvent = SwingUtilities.convertMouseEvent(table, e, panel); panel.dispatchEvent(panelEvent); // This is necessary so that when a button is pressed and released // it gets rendered properly. Otherwise, the button may still appear // pressed down when it has been released. table.repaint(); } } public void stopEditing() { leftSideColumn.stopCellEditing(); rightSideColumn.stopCellEditing(); } public void reloadTable() { table.tableChanged(new TableModelEvent(tableModel)); } // ************************************* REQUIRED IMPLEMENTATION METHODS ************************************* /** * Method to get rid of this WaveformWindow. Called by WindowFrame when * that windowFrame gets closed. */ public void finished() { for(Panel wp : wavePanels) { wp.finished(); } overall.removeComponentListener(wcl); highlighter.delete(); if (sd != null) sd.finished(); } public void fullRepaint() { repaint(); } public void repaint() { for(Panel wp : wavePanels) { wp.repaintContents(); } if (mainHorizRulerPanel != null) mainHorizRulerPanel.repaint(); } /** * Method to initialize for a new text search. * @param search the string to locate. * @param caseSensitive true to match only where the case is the same. * @param regExp true if the search string is a regular expression. * @param whatToSearch a collection of text types to consider. * @param codeRestr a restriction on types of Code to consider (null to consider all Code values). * @param unitRestr a restriction on types of Units to consider (null to consider all Unit values). * @param highlightedOnly true to search only in the highlighted area. */ public void initTextSearch(String search, boolean caseSensitive, boolean regExp, Set<TextUtils.WhatToSearch> whatToSearch, CodeExpression.Code codeRestr, TextDescriptor.Unit unitRestr, boolean highlightedOnly) { System.out.println("Text search not implemented for waveform windows"); } /** * Method to find the next occurrence of a string. * @param reverse true to find in the reverse direction. * @return true if something was found. */ public boolean findNextText(boolean reverse) { return false; } /** * Method to replace the text that was just selected with findNextText(). * @param replace the new text to replace. */ public void replaceText(String replace) {} /** * Method to replace all selected text. * @param replace the new text to replace everywhere. */ public void replaceAllText(String replace) {} /** * Method to export directly PNG file. * @param ep printable object. * @param filePath */ public void writeImage(ElectricPrinter ep, String filePath) { BufferedImage img = getPrintImage(ep); PNG.writeImage(img, filePath); } private int oldBackground, oldForeground; private boolean changedColors = false; /** * Method to intialize for printing. * @param ep the ElectricPrinter object. * @param pageFormat information about the print job. * @return true if no erros were found during initialization. */ public boolean initializePrinting(ElectricPrinter ep, PageFormat pageFormat) { oldForeground = User.getColor(User.ColorPrefType.WAVE_FOREGROUND); oldBackground = User.getColor(User.ColorPrefType.WAVE_BACKGROUND); User.setColor(User.ColorPrefType.WAVE_FOREGROUND, 0); User.setColor(User.ColorPrefType.WAVE_BACKGROUND, 0xFFFFFF); changedColors = true; PrinterJob pj = ep.getPrintJob(); if (pj == null) return false; // error ColorSupported cs = pj.getPrintService().getAttribute(ColorSupported.class); if (cs == null) return false; // error nowPrinting = 1; if (cs.getValue() == 0) nowPrinting = 2; Dimension oldSize = ep.getOldSize(); int pageWid = (int)pageFormat.getImageableWidth() * ep.getDesiredDPI() / 72; int pageHei = (int)pageFormat.getImageableHeight() * ep.getDesiredDPI() / 72; double scaleX = (double)pageWid / (double)oldSize.width; double scaleY = (double)pageHei / (double)oldSize.height; double scale = Math.min(scaleX, scaleY); pageWid = (int)(oldSize.width * scale); pageHei = (int)(oldSize.height * scale); overall.setSize(pageWid, pageHei); overall.validate(); redrawAllPanels(); overall.repaint(); return true; } /** * Method to print window using offscreen canvas. * @param ep printable object. * @return the image to print (null on error). */ public BufferedImage getPrintImage(ElectricPrinter ep) { BufferedImage bImage = ep.getBufferedImage(); Dimension sz = getPanel().getSize(); if (bImage == null) { bImage = (BufferedImage)(overall.createImage(sz.width, sz.height)); ep.setBufferedImage(bImage); } Graphics2D g2d = (Graphics2D)ep.getGraphics(); if (g2d == null) { g2d = bImage.createGraphics(); } // scale if there was an old image size Dimension szOld = ep.getOldSize(); if (szOld != null) { double scaleX = (double)sz.width / (double)szOld.width; double scaleY = (double)sz.height / (double)szOld.height; double gSX = (double)szOld.width / (double)szOld.height; double gSY = gSX * scaleY / scaleX; g2d.translate(ep.getPageFormat().getImageableX(), ep.getPageFormat().getImageableY()); g2d.scale(72.0 / ep.getDesiredDPI() / gSX, 72.0 / ep.getDesiredDPI() / gSY); } overall.paint(g2d);// if (mainHorizRulerPanel != null)// mainHorizRulerPanel.paint(g2d); if (changedColors) { User.setColor(User.ColorPrefType.WAVE_FOREGROUND, oldForeground); User.setColor(User.ColorPrefType.WAVE_BACKGROUND, oldBackground); changedColors = false; } nowPrinting = 0; return bImage; } /** * Method to pan along X or Y according to fixed amount of ticks * @param direction 0 for horizontal, 1 for vertical. * @param panningAmounts an array of distances, indexed by the current panning distance index. * @param ticks the number of steps to take (usually 1 or -1). */ public void panXOrY(int direction, double[] panningAmounts, int ticks) { // determine the panel extent double hRange = maxXPosition - minXPosition; double vRange = -1; double vRangeAny = -1; for(Panel wp : wavePanels) { vRangeAny = wp.getYAxisRange(); if (wp.isSelected()) { hRange = wp.getMaxXAxis() - wp.getMinXAxis(); vRange = wp.getYAxisRange(); break; } } if (vRange < 0) vRange = vRangeAny; double distance = ticks * panningAmounts[User.getPanningDistance()]; for(Panel wp : wavePanels) { if (direction == 0) { // pan horizontally if (!xAxisLocked && !wp.isSelected()) continue; double low = wp.getMinXAxis() - hRange * distance; double high = wp.getMaxXAxis() - hRange * distance; wp.setXAxisRange(low, high); } else { // pan vertically if (!wp.isSelected()) continue; double low = wp.getYAxisLowValue() - vRange * distance; double high = wp.getYAxisHighValue() - vRange * distance; wp.setYAxisRange(low, high); } wp.repaintWithRulers(); } } /** * Method to shift the panels so that the current cursor location becomes the center. */ public void centerCursor() { Panel pan = Panel.getCurrentPanel(); if (pan == null) return; int x = Panel.getCurrentXPos(); if (x < 0) return; Dimension dim = pan.getSize(); double startX = pan.convertXScreenToData(x); double endX = pan.convertXScreenToData(dim.width/2); double dXValue = endX - startX; for(Iterator<Panel> it = getPanels(); it.hasNext(); ) { Panel wp = it.next(); if (!isXAxisLocked() && wp != pan) continue; wp.setXAxisRange(wp.getMinXAxis() - dXValue, wp.getMaxXAxis() - dXValue); wp.repaintWithRulers(); } } /** * Method to set the window title. */ public void setWindowTitle() { if (wf == null) return; String title = ""; if (sd.getEngine() != null) title = "Simulation of "; else title = "Waveforms of "; if (sd != null && sd.getDataType() != null) { if (sd.getEngine() != null) title = sd.getDataType().getName() + " simulation of "; else title = sd.getDataType().getName() + " of "; } wf.setTitle(wf.composeTitle(sd.getCell(), title, 0)); } /** * Method to return the top-level JPanel for this WaveformWindow. * The actual WaveformWindow object is below the top level, surrounded by scroll bars and other display artifacts. * @return the top-level JPanel for this WaveformWindow. */ public JPanel getPanel() { return overall; } public void setCursor(Cursor cursor) { overall.setCursor(cursor); if (USETABLES) { table.setCursor(cursor); } else { split.setCursor(cursor); right.setCursor(cursor); } for (JPanel p : wavePanels) { p.setCursor(cursor); } } public void setCell(Cell cell, VarContext context, WindowFrame.DisplayAttributes displayAttributes) { sd.setCell(cell); setWindowTitle(); } /** * Method to return the cell that is shown in this window. * @return the cell that is shown in this window. */ public Cell getCell() { return sd.getCell(); } /** * Method to return the stimulus information associated with this WaveformWindow. * @return the stimulus information associated with this WaveformWindow. */ public Stimuli getSimData() { return sd; } public void bottomScrollChanged(int e) {} public void rightScrollChanged(int e) {} // ************************************* WINDOW CONTROL ************************************* /** * Method to return the associated schematics or layout window for this WaveformWindow. * @return the other window that is cross-linked to this. * Returns null if none can be found. */ private WindowFrame findSchematicsWindow() { Cell cell = getCell(); if (cell == null) return null; // look for the original cell to highlight it for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); if (wf.getContent().getCell() != cell) continue; if (wf.getContent() instanceof EditWindow) return wf; } return null; } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -