Skip to content

Swingtut #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
423eb37
Swing tutorials under examples.
Sep 24, 2014
a6e73e3
Compile examples in the Travis build.
retronym Sep 24, 2014
6d1dcde
Merge remote-tracking branch 'scala-swing/java7' into java7
Sep 25, 2014
a74866b
SimpleSwingApplication extended by companion objects.
Sep 26, 2014
aa41edd
Merge branch 'review/18/travis-examples' of https://github.com/retron…
Sep 26, 2014
e4c86d3
Make lazy val references to the MainFrame variable in most of the tut…
Sep 26, 2014
3323bcf
Remove the spurious comment that the process method is never called b…
Sep 26, 2014
390b515
Remove unneeded references to the peer's minimumSize, preferredSize, …
Sep 26, 2014
cdce672
Get rid of deprecated procedure syntax instances.
Sep 26, 2014
9d138a4
Factor out common code that is getting icons from the same directory.
Sep 26, 2014
5288a4e
Fix the caret event handling. Fix undo and redo menu items using jav…
Sep 27, 2014
1dc107e
Rewrite of the undo and redo actions so that no use is made of the me…
Sep 27, 2014
8135ffb
Move TextPane from the end of TextSampleDemo into /scala/swing as a S…
Sep 27, 2014
7f3f70a
Fixed a comment in Utils that said a null is returned when instead an…
Sep 27, 2014
aeddf89
Remove scala.swing.examples.tutorials.components.Utils. It is used b…
Sep 27, 2014
014216e
Adding the example source directory as a source path in Eclipse added…
Sep 27, 2014
bc4796a
Move the ToolBar out of the tutorial code and into scala/swing. Chan…
Sep 27, 2014
9633305
Simplify exception handling in FocusConceptsDemo by using NonFatal.
Sep 27, 2014
893b432
Replace bad var declarations with good val declarations.
Sep 27, 2014
1284635
Unused methods removed.
Sep 27, 2014
d011558
Copyrights and comments for ToolBar.
Sep 27, 2014
0b494f1
Dead code removal. Null and var declaration suppression.
Sep 27, 2014
282aa7e
Return an ImageIcon option instead of an ImageIcon from the createNav…
Sep 27, 2014
7af6112
BorderDemo little closer to original
andy1138 Sep 29, 2014
a6f21c8
BorderDemo little closer to original
andy1138 Sep 29, 2014
1559369
Merge pull request #2 from andy1138/tutorial
jacobsallan Sep 30, 2014
ef3aadb
Moved look and feel setup code to get rid of some more statements tha…
Sep 30, 2014
2063ea2
Merge branch 'swingtut' into swingtut2
Sep 30, 2014
222558e
Simplify createImageIcon so that it uses a map instead of an
Oct 1, 2014
81a3361
Remove a reference to the ComboBox peer to set editable to true. This
Oct 1, 2014
f0ea41e
Scaladoc changes to files using BorderDemo as a template. Replacement
Oct 1, 2014
cbc70f9
FlowLayout, GridLayout, GridBagLayout demos scalified.
Oct 1, 2014
8c0754a
Events demos Beeper and ListSelectionDemo. Fixed the orientation of the
Oct 1, 2014
943ef11
Merged changes from Andy Hicks, mostly having to do with createImageI…
Oct 1, 2014
4ae0185
Use javax.swing.Component constants when assigning to xLayoutAlignment.
Oct 3, 2014
93f97aa
Use repaint from scala.swing.UIElement instead of the repaint method …
Oct 3, 2014
3e5040b
Merge with andy1138-tutorial. In the process, ListDemo's cancel butt…
Oct 6, 2014
722a2a3
Fix up borders, x-alignments, and RigidBoxes that were in the origina…
Oct 6, 2014
db8615a
Undecorated window case enabled in FrameDemo2. Removed all uses of p…
Oct 6, 2014
19fd1b4
Remove half the files for lack of support in scala swing in the java7…
Oct 7, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ build.properties
/.cache
/.idea
/.settings
/examples/.classpath
/examples/.project
scala-swing.iml

# bak files produced by ./cleanup-commit
*.bak
Expand All @@ -42,4 +45,4 @@ qbin
# Mac specific, but that is common enough a dev platform to warrant inclusion.
.DS_Store

target/
target/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: scala
script:
- sbt ++$TRAVIS_SCALA_VERSION clean update compile test
- sbt ++$TRAVIS_SCALA_VERSION clean update compile test examples/compile
scala:
- 2.11.1

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en-us">
<title>Styled Text Sample</title>
<body>
<img src="images/dukeWaveRed.gif" width="64" height="64" alt="Waving Duke icon"/>
<p>This is an uneditable <code>EditorPane</code>,
which was <em>initialized</em>
with <strong>HTML</strong> text <font size=-2>from</font> a
<font size=+2>URL</font>.
</p>
An editor pane uses specialized editor kits
to read, write, display, and edit text of
different formats.
The Swing text package includes editor kits
for plain text, HTML, and RTF.
You can also develop
custom editor kits for other formats.
<!-- Start SiteCatalyst code -->
<script type="text/javascript" language="JavaScript" src="http://www.oracle.com/ocom/groups/systemobject/@mktg_admin/documents/systemobject/s_code_download.js"></script>
<script type="text/javascript" language="JavaScript" src="http://www.oracle.com/ocom/groups/systemobject/@mktg_admin/documents/systemobject/s_code.js"></script>
<noscript>
A browser with JavaScript enabled is required for this page to operate properly.
</noscript>

<!-- ********** DO NOT ALTER ANYTHING BELOW THIS LINE ! *********** -->
<!-- Below code will send the info to Omniture server -->
<script type="text/javascript" language="javascript">var s_code=s.t();if(s_code)document.write(s_code)</script>

<!-- End SiteCatalyst code -->
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle or the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scala.swing.examples.tutorials.components

import scala.swing._
import java.awt.Color

/**
* Tutorial: How to Use Borders
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/border.html]]
*
* Source code reference:
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/BorderDemoProject/src/components/BorderDemo.java]]
*
* BorderDemo.scala requires the following file:
* scala/swing/examples/tutorials/images/wavy.gif
*/
class BorderDemo extends GridPanel(1, 0) {

val paneEdge = Swing.EmptyBorder(0, 10, 10, 10)
val blackline = Swing.LineBorder(Color.black)
val raisedetched = Swing.EtchedBorder(Swing.Raised)
val loweredetched = Swing.EtchedBorder(Swing.Lowered)
val raisedbevel = Swing.BeveledBorder(Swing.Raised)
val loweredbevel = Swing.BeveledBorder(Swing.Lowered)
val empty = Swing.EmptyBorder


def addCompForBorder(bord: javax.swing.border.Border, description: String): Seq[Component] =
List(Swing.RigidBox(new Dimension(0, 10)), new GridPanel(1, 1) {
contents += new Label(description, Swing.EmptyIcon, Alignment.Center)
border = bord
})

//First pane: simple borders
val simpleBorders = new BoxPanel(Orientation.Vertical) {
contents ++=
addCompForBorder(blackline, "line border") ++
addCompForBorder(raisedetched, "raised etched border") ++
addCompForBorder(loweredetched, "lowered etched border") ++
addCompForBorder(raisedbevel, "raised bevel border") ++
addCompForBorder(loweredbevel, "lowered bevel border") ++
addCompForBorder(empty, "empty border")
}

//Second pane: matte borders
val matteBorders = new BoxPanel(Orientation.Vertical) {
border = paneEdge

val icon = BorderDemo.createImageIcon("/scala/swing/examples/tutorials/images/wavy.gif", "wavy-line border icon")

contents ++=
addCompForBorder(
Swing.MatteBorder(-1, -1, -1, -1, icon.getOrElse(null.asInstanceOf[javax.swing.Icon])),
"matte border (-1,-1,-1,-1,icon)") ++
addCompForBorder(
Swing.MatteBorder(1, 5, 1, 1, Color.red),
"matte border (1,5,1,1,Color.red)") ++
addCompForBorder(
Swing.MatteBorder(0, 20, 0, 0, icon.getOrElse(null.asInstanceOf[javax.swing.Icon])),
"matte border (0,20,0,0,icon)")
}

//Third pane: titled borders
val titledBorders = new BoxPanel(Orientation.Vertical) {
border = paneEdge

def titleBorder(border: javax.swing.border.Border, justification: Int, position: Int): javax.swing.border.Border = {
val titled = Swing.TitledBorder(border, "title")
titled.setTitleJustification(justification)
titled.setTitlePosition(position)
titled
}

contents ++=
addCompForBorder(
titleBorder(blackline, javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION),
"titled line border (centered, default pos.)") ++
addCompForBorder(
titleBorder(loweredetched, javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.DEFAULT_POSITION),
"titled lowered etched border (right just., default pos.)") ++
addCompForBorder(
titleBorder(loweredbevel, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP),
"titled lowered bevel border (default just., above top)") ++
addCompForBorder(
titleBorder(empty, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.BOTTOM),
"titled empty border (default just., bottom)")
}

//Fourth pane: compound borders
val compoundBorders = new BoxPanel(Orientation.Vertical) {
border = paneEdge

val titledCompound = Swing.TitledBorder(Swing.CompoundBorder(Swing.LineBorder(Color.red), Swing.CompoundBorder(Swing.BeveledBorder(Swing.Raised), Swing.BeveledBorder(Swing.Lowered))), "title")
titledCompound.setTitleJustification(javax.swing.border.TitledBorder.CENTER)
titledCompound.setTitlePosition(javax.swing.border.TitledBorder.BELOW_BOTTOM)

contents ++=
addCompForBorder(
Swing.CompoundBorder(raisedbevel, loweredbevel),
"compound border (two bevels)") ++
addCompForBorder(
Swing.CompoundBorder(Swing.LineBorder(Color.red), Swing.CompoundBorder(raisedbevel, loweredbevel)),
"compound border (add a red outline)") ++
addCompForBorder(
titledCompound,
"titled compound border (centered, below bottom)")
}


contents += new TabbedPane() {
tooltip = "<html>Blue Wavy Line border art crew:<br>&nbsp;&nbsp;&nbsp;Bill Pauley<br>&nbsp;&nbsp;&nbsp;Cris St. Aubyn<br>&nbsp;&nbsp;&nbsp;Ben Wronsky<br>&nbsp;&nbsp;&nbsp;Nathan Walrath<br>&nbsp;&nbsp;&nbsp;Tommy Adams, special consultant</html>"

pages += new TabbedPane.Page("Simple", simpleBorders)
pages += new TabbedPane.Page("Matte", matteBorders)
pages += new TabbedPane.Page("Titled", titledBorders)
pages += new TabbedPane.Page("Compound", compoundBorders)

selection.index = 0
}
}

object BorderDemo extends SimpleSwingApplication {
def createImageIcon(path: String, description: String): Option[javax.swing.ImageIcon] =
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))

lazy val top = new MainFrame() {
title = "BorderDemo"
//Create and set up the content pane.
contents = new BorderDemo()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Oracle or the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package scala.swing.examples.tutorials.components

import scala.swing._
import scala.swing.event.ButtonClicked

/**
* Tutorial: How to Use Buttons, Check Boxes, and Radio Buttons
* [[http://docs.oracle.com/javase/tutorial/uiswing/components/button.html]]
*
* Source code reference:
* [[http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ButtonDemoProject/src/components/ButtonDemo.java]]
*
* ButtonDemo.scala requires the following files:
* /scala/swing/examples/tutorials/images/right.gif
* /scala/swing/examples/tutorials/images/middle.gif
* /scala/swing/examples/tutorials/images/left.gif
*/
class ButtonDemo extends FlowPanel {
val leftButtonIcon = ButtonDemo.createImageIcon("/scala/swing/examples/tutorials/images/right.gif")
val middleButtonIcon = ButtonDemo.createImageIcon("/scala/swing/examples/tutorials/images/middle.gif")
val rightButtonIcon = ButtonDemo.createImageIcon("/scala/swing/examples/tutorials/images/left.gif")

val disable: Button = new Button("Disable middle button") {
leftButtonIcon.foreach( icon = _)
verticalTextPosition = Alignment.Center
horizontalTextPosition = Alignment.Leading
mnemonic = event.Key.D
tooltip = "Click this button to disable the middle button."
}

val middle: Button = new Button("Middle button") {
middleButtonIcon.foreach( icon = _ )
verticalTextPosition = Alignment.Bottom
horizontalTextPosition = Alignment.Center
mnemonic = event.Key.M
tooltip = "This middle button does nothing when you click it."
}

val enable: Button = new Button("Enable middle button") {
rightButtonIcon.foreach( icon = _ )
enabled = false
mnemonic = event.Key.E
tooltip = "Click this button to enable the middle button."
}

contents += disable
contents += middle
contents += enable

listenTo(disable)
listenTo(enable)

reactions += {
case ButtonClicked(`enable`) => enableMiddle()
case ButtonClicked(`disable`) => disableMiddle()
}

def enableMiddle(): Unit = {
enable.enabled = false
middle.enabled = true
disable.enabled = true
}

def disableMiddle(): Unit = {
enable.enabled = true
middle.enabled = false
disable.enabled = false
}
}

object ButtonDemo extends SimpleSwingApplication {
def createImageIcon(path: String): Option[javax.swing.ImageIcon] =
Option(resourceFromClassloader(path)).map(imgURL => Swing.Icon(imgURL))

lazy val top = new MainFrame() {
title = "ButtonDemo"
javax.swing.UIManager.put("swing.boldMetal", false)

contents = new ButtonDemo()
}
}
Loading