惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - evilyzou

scala 的List foldLeft用法 Circumflex Scala中的Either的两个子类(Left,Right)的简单用法 Scala中的一些特殊字符用法 Scala中的PartialFunction在Lift当中的NamedPF应用 Lift当中的AnyVarTrati源码解析 SBT和IDEA 开发scala web程序 使用Sbt(一) scalatra web框架安装指南 ASP.NET MVC: Do You Know Where Your TempData Is? 使用IntelliJ IDEA, Maven and the jetty plugin调试web应用程序 Scala GraphViz DOT Parser Scala Standard library Scala 一些基本的语法 Scala 相关的资源和Blog Lift2.0发布 Linux 汇编语言开发指南 Linux2.6内核启动流程学习 [导入]C#强化系列文章五:动态代码的使用(反射和动态生成类) [导入]C#强化系列文章七:序列化和反序列化
scala的DynamicVariable用法
evilyzou · 2010-08-20 · via 博客园 - evilyzou
 package org.scalatra
import scala.util.DynamicVariable
import javax.swing._

/**
 * Created by IntelliJ IDEA.
 * User: evilyzou
 * Date: 2010-8-20
 * Time: 14:29:05
 * To change this template use File | Settings | File Templates.
 */

object SwingBuilder{
  case class Context(frame: Option[JFrame],parent: Option[JComponent])
}

class SwingBuilder{
  import SwingBuilder._
  val context=new DynamicVariable[Context](Context(None,None))

  def frame(title: String)(f: =>Unit)={
    val res=new JFrame(title)
    res.add(new JPanel())
    context.withValue(Context(Some(res),context.value.parent)){f;res}
  }

  def menuBar(f: =>Unit)={
    val mb=new JMenuBar()
    context.value.frame.foreach(_.setJMenuBar(mb))
    context.withValue(Context(context.value.frame,Some(mb))){f;mb}
  }

  def menu(title:String)(f: =>Unit)={
    val m=new JMenu(title)
    var m2=new JMenu(title+"Test")
    context.value.parent.foreach(_.asInstanceOf[JMenuBar].add(m))
    context.value.parent.foreach(_.asInstanceOf[JMenuBar].add(m2))
    context.withValue(Context(context.value.frame,Some(m))){f;m}
    context.withValue(Context(context.value.frame,Some(m2))){f;m2}
  }

  def menuItem(title:String)={
    val mi=new JMenuItem(title)
    context.value.parent.foreach(_.asInstanceOf[JMenu].add(mi))
  }
}

object Test{

  def main(args:Array[String]){
    val builder=new SwingBuilder()
    import builder._

    val f=frame("Demo"){
      val mb=menuBar{
        menu("File"){
          menuItem("New")
          menuItem("Open")
          menuItem("SSS")
      }
    }
    mb
  }
  f.setVisible(true)
}
}