Commit a12a9acc authored by buehlera's avatar buehlera
Browse files

first commit

parents
MIT LICENSE
Copyright (c) 2009
MIT Scheller Teacher Education Program
Eric Klopfer, Daniel Wendel, Ricarose Roque, Corey McCaffrey, Lunduo Ye, Aidan Ho, Brett Warne, Xudan
Liu, Hout Nga
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
OpenBlocks refactoring branch
=============================
This is a fork of [MIT OpenBlocks](http://education.mit.edu/drupal/openblocks)
(covered by the MIT license) for refactoring purposes.
The principal objective of the fork is to make the code more amenable to inclusion to other projects.
Getting Started:
------
$ mvn clean package
$ mvn exec:java -Dexec.mainClass="edu.mit.blocks.controller.WorkspaceController" -Dexec.args="support/lang_def.xml"
To do:
------
* upgrade code maintainability from the academic baseline to the commercial baseline
* replace static singletons with contexts and instances
* separate the model from the UI
Done:
-----
* move the various project packages from the main namespace to under the ``edu.mit.blocks`` package
* refactor out functionality such as network communication
* remove dependency to TableLayout, which doesn't appear to be actively maintained,
and really not even used in a very complex manner
Contributors:
-------------
In order of first appearance on commit logs:
* The original MIT team: Eric Klopfer, Daniel Wendel, Ricarose Roque, Corey McCaffrey, Lunduo Ye, Aidan Ho, Brett Warne, Xudan Liu, Hout Nga
* Mikael Gueck (https://github.com/mikaelhg)
* David Li (https://github.com/taweili)
* Philippe Cade (https://github.com/philippecade)
* Tony Graham / MenteaXML (https://github.com/MenteaXML)
Changes by letsgoING
=====================
Contact: info@letsgoing.de
Source: github.com/letsgoing
added Option to change Menu
changes:
- in loadBlockDrawerSets() added drawerType param + filter (PageDrawerLoadingUtils.java Line 185 + 201 + 211-214 + 232)
- in loadWorkspaceFrom() added drawerType param (Workspace.java line 836 + 843 + 849 + 855)
- in loadWorkspaceFrom() added drawerType param (WorkspaceController.java line 415 + 433 + 460 + 502)
- in loadProject() added drawerType param and moved workspace.loadWorkspaceFrom() in if/else (WorkspaceController.java line 499 + 516 + 519)
other changes:
- in mouseReleased() added clone functionality by rightClick + CTRL (RenderableBlock.java line 1917 - 1921)
- in Page() removed "add collapse Button" (Page.java line 176)
- in paintComponent() removed "paint label" (Page.java line 1150 - 1166)
for zoom:
- added setValue and getValue method in ZoomSlider class (ZoomSlider.java line 60 - 70)
- changed calculation for unzoomed block-position in setWorkspaceZoom() (Workspace.java line 550 - 561)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Document : lang_def.dtd
Description:
This defines the language and initial workspace setup.
-->
<!ELEMENT BlockLangDef ( BlockConnectorShapes, BlockGenuses, BlockFamilies?, BlockDrawerSets?, Pages?, TrashCan?, MiniMap?)>
<!--This defines a mapping between block connector shape type to number-->
<!ELEMENT BlockConnectorShapes (BlockConnectorShape*)>
<!ELEMENT BlockConnectorShape EMPTY>
<!ATTLIST BlockConnectorShape shape-type CDATA #REQUIRED>
<!ATTLIST BlockConnectorShape shape-number CDATA #REQUIRED>
<!ELEMENT BlockGenuses (BlockGenus*)>
<!--This defines a single block genus-->
<!ELEMENT BlockGenus (description?, BlockConnectors?,Stubs?, Images?, LangSpecProperties?)>
<!ATTLIST BlockGenus name CDATA #REQUIRED>
<!ATTLIST BlockGenus initlabel CDATA #REQUIRED>
<!-- the kind of a genus can affect the rendering of a block. relevant kinds are:
- command: performs an operation and may take in more than one input
- data: returns primitive values such as number, string, boolean
- function: takes in an input and performs an operation to produce an ouput
-->
<!ATTLIST BlockGenus kind CDATA #REQUIRED>
<!ATTLIST BlockGenus color CDATA #REQUIRED>
<!ATTLIST BlockGenus editable-label (yes|no) "no">
<!ATTLIST BlockGenus label-unique (yes|no) "no">
<!ATTLIST BlockGenus is-label-value (yes|no) "no">
<!ATTLIST BlockGenus label-prefix CDATA #IMPLIED>
<!ATTLIST BlockGenus label-suffix CDATA #IMPLIED>
<!ATTLIST BlockGenus page-label-enabled (yes|no) "no">
<!--is-starter and is-terminator only apply to blocks of kind: command -->
<!ATTLIST BlockGenus is-starter (yes|no) "no">
<!ATTLIST BlockGenus is-terminator (yes|no) "no">
<!--This defines a block description and the description of its block arguments-->
<!ELEMENT arg EMPTY>
<!ATTLIST arg n CDATA #REQUIRED name CDATA #IMPLIED>
<!ELEMENT description (text, arg-description*)>
<!ELEMENT text (#PCDATA|note|em|i|br|arg)*>
<!ELEMENT arg-description (#PCDATA)>
<!ATTLIST arg-description n CDATA #REQUIRED name CDATA #REQUIRED>
<!ELEMENT note (#PCDATA|arg|i)*>
<!ELEMENT em (#PCDATA)>
<!ELEMENT i (#PCDATA)>
<!ELEMENT br (#PCDATA)>
<!--BlockConnectors are where blocks get connected-->
<!ELEMENT BlockConnectors (BlockConnector*)>
<!ELEMENT BlockConnector (DefaultArg?)>
<!ATTLIST BlockConnector label CDATA #IMPLIED>
<!ATTLIST BlockConnector label-editable (yes|no) "no">
<!-- Order matters with socket connectors and at most one plug is allowed (no multiple return types) -->
<!ATTLIST BlockConnector connector-kind (plug|socket) #REQUIRED>
<!-- for connector-type use the shape-type values specified in block connectors-->
<!ATTLIST BlockConnector connector-type CDATA #REQUIRED>
<!ATTLIST BlockConnector position-type (single|mirror|bottom) "single">
<!ATTLIST BlockConnector is-expandable (yes|no) "no">
<!ELEMENT DefaultArg EMPTY>
<!ATTLIST DefaultArg genus-name CDATA #REQUIRED>
<!ATTLIST DefaultArg label CDATA #IMPLIED>
<!ELEMENT Stubs (Stub*)>
<!--This defines a stub of a block, so that the block can exist as a single entity and have mini-references to it-->
<!ELEMENT Stub (LangSpecProperties)>
<!ATTLIST Stub scope CDATA #IMPLIED>
<!ATTLIST Stub stub-genus (getter|setter|caller|agent|inc) #REQUIRED>
<!-- Defines the images that are drawn on the block itself.
Note: For now, only one image is enabled and wrap-text and image-editable have no effect.
Note: make sure FileLocation specified is relative to workspace directory -->
<!ELEMENT Images (Image)>
<!ELEMENT Image (FileLocation)>
<!ATTLIST Image wrap-text (yes|no) "no">
<!ATTLIST Image image-editable (yes|no) "no">
<!ATTLIST Image block-location (center|east|west|north|south|southeast|southwest|northeast|northwest) "center">
<!ATTLIST Image width CDATA #IMPLIED>
<!ATTLIST Image height CDATA #IMPLIED>
<!ELEMENT FileLocation (#PCDATA)>
<!ELEMENT LangSpecProperties (LangSpecProperty*)>
<!ELEMENT LangSpecProperty (#PCDATA)>
<!ATTLIST LangSpecProperty key CDATA #REQUIRED>
<!ATTLIST LangSpecProperty value CDATA #REQUIRED>
<!--This defines a BlockGenus Family-->
<!ELEMENT BlockFamilies (BlockFamily*)>
<!ELEMENT BlockFamily (FamilyMember*)>
<!ELEMENT FamilyMember (#PCDATA)>
<!-- Defines BlockDrawerSets and their Block Drawer content-->
<!ELEMENT BlockDrawerSets (BlockDrawerSet*)>
<!ELEMENT BlockDrawerSet (BlockDrawer*)>
<!ATTLIST BlockDrawerSet type (bar|stack) "bar">
<!ATTLIST BlockDrawerSet name CDATA #REQUIRED>
<!ATTLIST BlockDrawerSet location (east|west|north|south|northeast|southeast|southwest|northwest) "west">
<!-- window-per-drawer specifies if each drawer should be its own draggable window. otherwise, all the drawers
are contained within one draggable window and only one drawer can be opened at once.
Whether or not the window is draggable depends if drawer-draggable is set to "yes." -->
<!ATTLIST BlockDrawerSet window-per-drawer (yes|no) "yes">
<!ATTLIST BlockDrawerSet drawer-draggable (yes|no) "yes">
<!-- the width of all the drawers within this set -->
<!ATTLIST BlockDrawerSet width CDATA #IMPLIED>
<!--This defines BlockDrawers and their content-->
<!ELEMENT BlockDrawer ( (BlockGenusMember | Separator | NextLine)* )>
<!ATTLIST BlockDrawer name CDATA #REQUIRED>
<!ATTLIST BlockDrawer type (default|factory|page|custom) "default">
<!ATTLIST BlockDrawer is-open (yes|no) "no">
<!ATTLIST BlockDrawer button-color CDATA #REQUIRED>
<!ELEMENT BlockGenusMember (#PCDATA)>
<!ELEMENT Separator EMPTY>
<!ELEMENT NextLine EMPTY>
<!-- Defines Pages dividing the Block Canvas and the optional PageDrawers associated with them
Each Page can have only one PageDrawer.
For now, every page must have a drawer or no pages can have drawers.
The block canvas need not contain any pages. You may choose to have
a blank canvas instead of a canvas of pages.
-->
<!ELEMENT Pages (Page*)>
<!--
drawer-with-page auto generates a new drawer for each new page created by a user
and creates an empty drawer for each page that does not specify a page drawer
-->
<!ATTLIST Pages drawer-with-page (yes|no) "no">
<!ELEMENT Page (PageDrawer?)>
<!ATTLIST Page page-name CDATA #REQUIRED>
<!ATTLIST Page page-width CDATA #REQUIRED>
<!ATTLIST Page page-drawer CDATA #IMPLIED>
<!ATTLIST Page page-color CDATA #IMPLIED>
<!ATTLIST Page page-shape CDATA #IMPLIED>
<!ELEMENT PageDrawer (BlockGenusMember*)>
<!-- If specified a trash can will appear on the workspace.
For both of its child elements, a location for the images should be specified relative to the working directory.
The open trash image appears when a user drags a block over the trashcan. The closed trash image is the default
image during steady state.
-->
<!ELEMENT TrashCan (OpenTrashImage, ClosedTrashImage)>
<!ELEMENT OpenTrashImage (#PCDATA)>
<!ELEMENT ClosedTrashImage (#PCDATA)>
<!-- By default, a minimap will always appear in the upper right corner
of the block canvas, unless enabled is set to "no."
-->
<!ELEMENT MiniMap EMPTY>
<!ATTLIST MiniMap enabled (yes|no) "yes">
<!-- By default, typeblocking will be enabled, such that when the user types onto the canvas
blocks will fly out that match the entered text.
-->
<!ELEMENT Typeblocking EMPTY>
<!ATTLIST Typeblocking enabled (yes|no) "yes">
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.mit</groupId>
<artifactId>openblocks</artifactId>
<packaging>jar</packaging>
<version>1.0.2-SNAPSHOT</version>
<name>openblocks</name>
<url>https://github.com/mikaelhg/openblocks</url>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<mainClass>edu.mit.blocks.controller.WorkspaceController</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>edu.mit.blocks.controller.WorkspaceController</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<show>private</show>
<tags>
<tag>
<name>effects</name>
<placement>a</placement>
<head>Effects:</head>
</tag>
<tag>
<name>modifies</name>
<placement>a</placement>
<head>Modifies:</head>
</tag>
<tag>
<name>overrides</name>
<placement>a</placement>
<head>Overrides:</head>
</tag>
<tag>
<name>requires</name>
<placement>a</placement>
<head>Requires:</head>
</tag>
<tag>
<name>specfield</name>
<placement>a</placement>
<head>Spec field:</head>
</tag>
</tags>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<show>public</show>
<tags>
<tag>
<name>effects</name>
<placement>a</placement>
<head>Effects:</head>
</tag>
<tag>
<name>modifies</name>
<placement>a</placement>
<head>Modifies:</head>
</tag>
<tag>
<name>overrides</name>
<placement>a</placement>
<head>Overrides:</head>
</tag>
<tag>
<name>requires</name>
<placement>a</placement>
<head>Requires:</head>
</tag>
<tag>
<name>specfield</name>
<placement>a</placement>
<head>Spec field:</head>
</tag>
</tags>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.16</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package edu.mit.blocks.codeblocks;
import edu.mit.blocks.codeblockutil.Sound;
import edu.mit.blocks.codeblockutil.SoundManager;
import edu.mit.blocks.renderable.RenderableBlock;
import edu.mit.blocks.workspace.Workspace;
import edu.mit.blocks.workspace.WorkspaceEvent;
/**
* A class that stores information about a potential block connection.
*
* Each BlockLink instance stores the Block IDs of the "plug" and "socket"
* and two block connectors, one from each, with a possible connection.
*
* In block linking, a "plug" can be either a before or plug connector,
* while a "socket" can either be a after or socket connector. Plugs can only
* connect to other socket connectors, while before connectors can connect to
* after and command socket connectors.
*/
public class BlockLink {
private final Workspace workspace;
private static Sound clickSound;
private Long plugBlockID;
private Long socketBlockID;
private Long lastPlugBlockID;
private BlockConnector plug;
private BlockConnector socket;
//information regarding the last BlockLink instance
private static Long lastPlugID;
private static Long lastSocketID;
private static BlockConnector lastPlug;
private static BlockConnector lastSocket;
private static BlockLink lastLink;
/**
* Private constructor to (somewhat) limit object creation
* @param workspace The corresponding workspace
* @param block1
* @param block2
* @param socket1
* @param socket2
*/
private BlockLink(Workspace workspace, Block block1, Block block2, BlockConnector socket1, BlockConnector socket2) {
this.workspace = workspace;
boolean isPlug1 = (block1.hasPlug() && block1.getPlug() == socket1)
|| (block1.hasBeforeConnector() && block1.getBeforeConnector() == socket1);
boolean isPlug2 = (block2.hasPlug() && block2.getPlug() == socket2)
|| (block2.hasBeforeConnector() && block2.getBeforeConnector() == socket2);
if (!(isPlug1 ^ isPlug2)) {
// bad news... there should be only one plug