|
Scala example source code file (BorderPanel.scala)
The Scala BorderPanel.scala source code/* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2007-2011, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ package scala.swing import java.awt.BorderLayout object BorderPanel { /** * The position of a component in a <code>BorderPanel */ object Position extends Enumeration { val North = Value(BorderLayout.NORTH) val South = Value(BorderLayout.SOUTH) val West = Value(BorderLayout.WEST) val East = Value(BorderLayout.EAST) val Center = Value(BorderLayout.CENTER) } private[swing] def wrapPosition(s: String): Position.Value = s match { case BorderLayout.NORTH => Position.North case BorderLayout.SOUTH => Position.South case BorderLayout.WEST => Position.West case BorderLayout.EAST => Position.East case BorderLayout.CENTER => Position.Center } } /** * A container that arranges its children around a central component that * takes most of the space. The other children are placed on one of four * borders: north, east, south, west. * * @see javax.swing.BorderLayout */ class BorderPanel extends Panel with LayoutContainer { import BorderPanel._ def layoutManager = peer.getLayout.asInstanceOf[BorderLayout] override lazy val peer = new javax.swing.JPanel(new BorderLayout) with SuperMixin type Constraints = Position.Value protected def constraintsFor(comp: Component) = wrapPosition(layoutManager.getConstraints(comp.peer).asInstanceOf[String]) protected def areValid(c: Constraints): (Boolean, String) = (true, "") protected def add(c: Component, l: Constraints) { // we need to remove previous components with the same constraints as the new one, // otherwise the layout manager loses track of the old one val old = layoutManager.getLayoutComponent(l.toString) if(old != null) peer.remove(old) peer.add(c.peer, l.toString) } } Other Scala examples (source code examples)Here is a short list of links related to this Scala BorderPanel.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.