Swing 中的音频波形选择
我正在研究音频编辑器。每个波形都在自己的 JPanel 中绘制。这些 JPanel 位于另一个 JPanel 内,该 JPanel 是波形和时间线的容器。这个容器位于 JScrollPane 中。
现在我必须为 Selection 类编写视图,但我不知道哪个 Swing 组件是最好的。选择应该在波形(或所有容器)上绘制,应该非常透明并且应该可以拖动(不能调整大小,只是可以拖动)轴。
你会怎么做?
I'm working on audio editor. Each waveform is drawn in own JPanel. Those JPanels are inside another JPanel, which is a container for waveforms and the timeline. And this container is in a JScrollPane.
Now I have to write view for Selection class and I don't know which Swing component will be the best. Selection should be drawn over waveforms (or all container), should be quite transparent and should be draggable (not resizable, just draggable) along time axis.
How would you do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我做这件事时,我对 JComponent 进行了子类化。原因是波形查看器组件实际上不是容器。您不会设置布局管理器,也不会向其添加子组件等。您可以拥有可能类似于子组件的特殊组件,例如标志、注释等,但它们的行为可能不像 Swing 组件。除了使用您自己的版本之外,还可以轻松创建比 swing 更轻的组件。事实上,我有大部分这些概念:1 个或多个选择、循环点、标志、播放头等。
我的组件的工作原理如下:
这大致就是每个覆盖层实现的内容。还有其他几种方法用于处理事件调度、监听等。选择、标志、播放头、注释都实现了 WaveformOverlay。在 AudioView.paintComponent() 方法内部,将其绘制的一部分委托给可见视图中的每个覆盖层。
同样的概念也适用于鼠标移动事件、鼠标点击等。
When I did this exact thing I subclassed JComponent. Reason is a Waveform viewer component really isn't a container. You aren't going to set a layout manager, or have children you add to it, etc. You could have special components that might be like children, say flags, annotations, etc, but they probably won't act like Swing components. Besides using your own version of these makes it really easy to create lighter weight components than swing. In fact I had most of those concepts: 1 or more selections, loop points, flags, play head, etc.
My component worked something like this:
This is roughly what each overlay implements. There are several other methods for handling event dispatching, listening, etc. Selections, flags, playhead, annotations all implement WaveformOverlay. Inside the AudioView.paintComponent() method delegates a portion of it's drawing to each overlay within the visible view.
Same concept is applied for mouse motion events, mouse clicks, etc.
问题与回答,查找局部最小值,可能会建议一种在波形中拖动选择的方法。
附录:要实现 z 排序,请考虑 分层窗格。
The Question & Answer, Finding local Minimum, may suggest an approach to dragging a selection in a waveform.
Addendum: To effect z-ordering, consider a layered pane.