├── .classpath ├── .hgignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.jdt.ui.prefs ├── README.eclipse ├── README.netbeans ├── TWL Logo.png ├── TWL Logo.svg ├── build.xml ├── debug-switches.txt ├── libs └── lwjgl_util_applet.jar ├── manifest.mf ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── project.properties └── project.xml ├── pom.xml_inactive ├── src-beans ├── de │ └── matthiasmann │ │ └── twl │ │ └── input │ │ └── LWJGLInput.java └── java │ └── beans │ ├── PropertyChangeEvent.java │ ├── PropertyChangeListener.java │ └── PropertyChangeSupport.java ├── src └── de │ └── matthiasmann │ └── twl │ ├── ActionCallback.java │ ├── ActionMap.java │ ├── Alignment.java │ ├── AnimatedWindow.java │ ├── AnimationState.java │ ├── Border.java │ ├── BorderLayout.java │ ├── BoxLayout.java │ ├── Button.java │ ├── CallbackWithReason.java │ ├── Clipboard.java │ ├── Color.java │ ├── ColorSelector.java │ ├── ColumnLayout.java │ ├── ComboBox.java │ ├── ComboBoxBase.java │ ├── Container.java │ ├── DatePicker.java │ ├── DatePickerComboBox.java │ ├── DebugHook.java │ ├── DesktopArea.java │ ├── DialogLayout.java │ ├── Dimension.java │ ├── DraggableButton.java │ ├── EditField.java │ ├── EditFieldAutoCompletionWindow.java │ ├── Event.java │ ├── FPSCounter.java │ ├── FileSelector.java │ ├── FileTable.java │ ├── FocusGainedCause.java │ ├── FolderBrowser.java │ ├── GUI.java │ ├── Graph.java │ ├── HAlignment.java │ ├── InfoWindow.java │ ├── InputMap.java │ ├── KeyStroke.java │ ├── Label.java │ ├── ListBox.java │ ├── ListBoxDisplay.java │ ├── Menu.java │ ├── MenuAction.java │ ├── MenuCheckbox.java │ ├── MenuElement.java │ ├── MenuManager.java │ ├── MenuSpacer.java │ ├── MouseSensitiveRectangle.java │ ├── ParameterList.java │ ├── ParameterMap.java │ ├── PopupWindow.java │ ├── PositionAnimatedPanel.java │ ├── ProgressBar.java │ ├── PropertySheet.java │ ├── RadialPopupMenu.java │ ├── Rect.java │ ├── ResizableFrame.java │ ├── ScrollPane.java │ ├── Scrollbar.java │ ├── SimpleDialog.java │ ├── SplitPane.java │ ├── TabbedPane.java │ ├── Table.java │ ├── TableBase.java │ ├── TableRowSelectionManager.java │ ├── TableSearchWindow.java │ ├── TableSelectionManager.java │ ├── TextArea.java │ ├── TextWidget.java │ ├── ThemeInfo.java │ ├── Timer.java │ ├── ToggleButton.java │ ├── TreeComboBox.java │ ├── TreePathDisplay.java │ ├── TreeTable.java │ ├── ValueAdjuster.java │ ├── ValueAdjusterFloat.java │ ├── ValueAdjusterInt.java │ ├── WheelWidget.java │ ├── Widget.java │ ├── input │ ├── Input.java │ └── lwjgl │ │ └── LWJGLInput.java │ ├── license.html │ ├── license.txt │ ├── model │ ├── AbstractColorSpace.java │ ├── AbstractEnumModel.java │ ├── AbstractFloatModel.java │ ├── AbstractIntegerModel.java │ ├── AbstractListModel.java │ ├── AbstractOptionModel.java │ ├── AbstractProperty.java │ ├── AbstractTableColumnHeaderModel.java │ ├── AbstractTableModel.java │ ├── AbstractTableSelectionModel.java │ ├── AbstractTreeTableModel.java │ ├── AbstractTreeTableNode.java │ ├── AutoCompletionDataSource.java │ ├── AutoCompletionResult.java │ ├── BitfieldBooleanModel.java │ ├── BooleanModel.java │ ├── ButtonModel.java │ ├── ColorModel.java │ ├── ColorSpace.java │ ├── ColorSpaceHSL.java │ ├── CombinedListModel.java │ ├── DateModel.java │ ├── DefaultEditFieldModel.java │ ├── DefaultTableSelectionModel.java │ ├── EditFieldModel.java │ ├── EnumListModel.java │ ├── EnumModel.java │ ├── FileSystemAutoCompletionDataSource.java │ ├── FileSystemModel.java │ ├── FileSystemTreeModel.java │ ├── FloatModel.java │ ├── GraphLineModel.java │ ├── GraphModel.java │ ├── HasCallback.java │ ├── IntegerModel.java │ ├── JavaFileSystemModel.java │ ├── ListModel.java │ ├── ListSelectionModel.java │ ├── MRUListModel.java │ ├── ObservableCharSequence.java │ ├── OptionBooleanModel.java │ ├── OptionEnumModel.java │ ├── PersistentBooleanModel.java │ ├── PersistentColorModel.java │ ├── PersistentEnumModel.java │ ├── PersistentIntegerModel.java │ ├── PersistentMRUListModel.java │ ├── PersistentStringModel.java │ ├── Property.java │ ├── PropertyList.java │ ├── ReorderListModel.java │ ├── SimpleAutoCompletionResult.java │ ├── SimpleBooleanModel.java │ ├── SimpleButtonModel.java │ ├── SimpleChangableListModel.java │ ├── SimpleDateModel.java │ ├── SimpleEnumModel.java │ ├── SimpleFloatModel.java │ ├── SimpleGraphLineModel.java │ ├── SimpleGraphModel.java │ ├── SimpleIntegerModel.java │ ├── SimpleListModel.java │ ├── SimpleListSelectionModel.java │ ├── SimpleMRUListModel.java │ ├── SimpleProperty.java │ ├── SimplePropertyList.java │ ├── SimpleStringModel.java │ ├── SimpleTableModel.java │ ├── SortOrder.java │ ├── StringAttributes.java │ ├── StringModel.java │ ├── TableColumnHeaderModel.java │ ├── TableModel.java │ ├── TableSelectionModel.java │ ├── TableSingleSelectionModel.java │ ├── ToggleButtonModel.java │ ├── TreeTableModel.java │ └── TreeTableNode.java │ ├── renderer │ ├── AnimationState.java │ ├── AttributedString.java │ ├── AttributedStringFontCache.java │ ├── CacheContext.java │ ├── DynamicImage.java │ ├── Font.java │ ├── Font2.java │ ├── FontCache.java │ ├── FontMapper.java │ ├── FontParameter.java │ ├── Gradient.java │ ├── Image.java │ ├── LineRenderer.java │ ├── MouseCursor.java │ ├── OffscreenRenderer.java │ ├── OffscreenSurface.java │ ├── QueriablePixels.java │ ├── Renderer.java │ ├── Resource.java │ ├── SupportsDrawRepeat.java │ ├── Texture.java │ └── lwjgl │ │ ├── BitmapFont.java │ │ ├── GradientImage.java │ │ ├── LWJGLAttributedStringFontCache.java │ │ ├── LWJGLCacheContext.java │ │ ├── LWJGLCursor.java │ │ ├── LWJGLDynamicImage.java │ │ ├── LWJGLFont.java │ │ ├── LWJGLFontCache.java │ │ ├── LWJGLRenderer.java │ │ ├── LWJGLTexture.java │ │ ├── SWCursor.java │ │ ├── TextureArea.java │ │ ├── TextureAreaBase.java │ │ ├── TextureAreaRotated.java │ │ ├── TextureAreaTiled.java │ │ ├── TextureDecoder.java │ │ ├── TexturePostProcessing.java │ │ ├── TintStack.java │ │ └── VertexArray.java │ ├── textarea │ ├── BoxAttribute.java │ ├── CSSStyle.java │ ├── HTMLTextAreaModel.java │ ├── OrderedListType.java │ ├── Parser.java │ ├── SimpleTextAreaModel.java │ ├── Style.java │ ├── StyleAttribute.java │ ├── StyleSheet.java │ ├── StyleSheetKey.java │ ├── StyleSheetResolver.java │ ├── TextAreaModel.java │ ├── TextDecoration.java │ ├── Value.java │ └── parser.flex │ ├── theme │ ├── AnimatedImage.java │ ├── ComposedImage.java │ ├── EmptyImage.java │ ├── GridImage.java │ ├── HasBorder.java │ ├── ImageAdjustments.java │ ├── ImageManager.java │ ├── ParameterListImpl.java │ ├── ParameterMapImpl.java │ ├── ParserUtil.java │ ├── RepeatImage.java │ ├── StateSelectImage.java │ ├── ThemeChildImpl.java │ ├── ThemeException.java │ ├── ThemeInfoImpl.java │ ├── ThemeManager.java │ └── theme.dtd │ └── utils │ ├── AbstractMathInterpreter.java │ ├── CallbackSupport.java │ ├── CascadedHashMap.java │ ├── ClassUtils.java │ ├── ClipStack.java │ ├── HashEntry.java │ ├── MultiStringReader.java │ ├── NaturalSortComparator.java │ ├── PNGDecoder.java │ ├── ParameterStringParser.java │ ├── SimpleMathParser.java │ ├── SizeSequence.java │ ├── SparseGrid.java │ ├── StateExpression.java │ ├── StateSelect.java │ ├── StateSelectOptimizer.java │ ├── StringList.java │ ├── TextUtil.java │ ├── TintAnimator.java │ ├── TypeMapping.java │ ├── WithRunnableCallback.java │ └── XMLParser.java └── test └── de └── matthiasmann └── twl ├── InputMapTest.java ├── model └── StringAttributesTest.java ├── textarea ├── HTMLTextAreaModelTest.java ├── OrderedListTypeTest.java ├── StyleAttributeTest.java └── StyleSheetTest.java └── utils ├── NaturalSortComparatorTest.java ├── SimpleMathParserTest.java ├── SizeSequenceTest.java ├── SparseGridTest.java ├── StateExpressionTest.java └── TextUtilTest.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | \.orig$ 2 | \.orig\..*$ 3 | \.chg\..*$ 4 | \.rej$ 5 | \.conflict\~$ 6 | ^dist/.* 7 | ^build/.* 8 | ^nbproject/private/.* 9 | ^bin/.* 10 | ^target/.* 11 | ^libs/progressbar\.png$ 12 | ^libs/TWLLogo\.png$ 13 | ^TWL-findbugs\.xml$ 14 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | twl 4 | Cloned from ssh://hg.l33tlabs.org//srv/hg/twl 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | #Thu Jun 17 21:54:26 EDT 2010 2 | eclipse.preferences.version=1 3 | formatter_profile=_TWL 4 | formatter_settings_version=11 5 | -------------------------------------------------------------------------------- /README.eclipse: -------------------------------------------------------------------------------- 1 | To set up Eclipse for building TWL, a couple steps are needed. 2 | 3 | Before starting, you will need to download the following packages, and unzip them somewhere on your PC: 4 | 5 | * lwjgl-2.4.2.zip from http://www.lwjgl.org/ 6 | * xpp3-1.1.4c_all.zip (or later) from http://www.extreme.indiana.edu/dist/java-repository/xpp3/distributions/ 7 | 8 | The contents of these files are included in the TWL required libraries archive: 9 | 10 | http://twl.l33tlabs.org/demo/twl.zip 11 | 12 | 1. Open the Eclipse preferences panel (Window menu, Preferences) 13 | 2. Navigate to Java/Build Path/User Libraries 14 | 3. Click "New" to add a User Library, name it "LWJGL". It is not a system library. 15 | 4. Select "LWJGL" in the list, and click "Add JARs". 16 | 5. Navigate to the LWJGL distribution directory, and select the following jar files: jinput.jar, lwjgl.jar, lwjgl_util.jar 17 | 6. Click "New" to add another User Library, name it "XPP3". It is not a system library. 18 | 7. Select "XPP3" in the list, and click "Add JARs". 19 | 8. Navigate to the XPP3 distribution directory, and select the following jar files: xpp3-1.1.4c.jar 20 | 21 | Once these steps are complete, TWL will compile. 22 | -------------------------------------------------------------------------------- /README.netbeans: -------------------------------------------------------------------------------- 1 | To compile TWL with Netbeans you need to setup the required libraries. 2 | 3 | These can be obtained from their websites: 4 | * lwjgl-2.4.2.zip (or later) from http://www.lwjgl.org/ 5 | * xpp3-1.1.4c_all.zip (or later) from http://www.extreme.indiana.edu/dist/java-repository/xpp3/distributions/ 6 | 7 | Unzip these files to a folder on your PC. 8 | Do not put them into your system, JDK/JRE or Netbeans folder. 9 | 10 | Alternatively you can download http://twl.l33tlabs.org/demo/twl.zip which contains all required libraries too. 11 | 12 | 13 | 1. Open the Netbeans library manager (Tools -> Libraries) 14 | 15 | 2.1. Click "New Library" to add a User Library, name it "LWJGL" and select as type "Class Library" (should be selected by default). 16 | 2.2. The library "LWJGL" should now be selected in the list. 17 | 2.3. On the "Classpath" tab click "Add JAR/Folder". 18 | 2.4. Navigate to the folder where you unziped the LWJGL zip, and select the following jar file: lwjgl.jar 19 | 20 | 3.1. Click "New" to add another User Library, name it "MXP1". 21 | 3.2. The library "MXP1" should now be selected in the list. 22 | 2.3. On the "Classpath" tab click "Add JAR/Folder". 23 | 2.4. Navigate to the folder where you unziped the xpp3 zip, and select the following jar file: xpp3-1.1.4c.jar 24 | 25 | 3. Close the dialog with "Ok" 26 | 27 | Once these steps are complete, TWL will compile. 28 | 29 | *XPP3 is an implementation of the MXP1 API 30 | -------------------------------------------------------------------------------- /TWL Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthiasMann/twl/4dbf6d482a5270e084e547a039960366b34291e8/TWL Logo.png -------------------------------------------------------------------------------- /debug-switches.txt: -------------------------------------------------------------------------------- 1 | The following VM properties can be set to enable additional debugging functions: 2 | 3 | -DdebugLayoutGroups=true DialogLayout.java 4 | Includes stack trace of DialogLayout construction/use 5 | when a error is detected in the layout description 6 | 7 | -DwarnOnUnhandledAction=true Widget.java 8 | Outputs a warning when a keyboard shortcut is mapped to 9 | an action and is not handled by any handler. 10 | -------------------------------------------------------------------------------- /libs/lwjgl_util_applet.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthiasMann/twl/4dbf6d482a5270e084e547a039960366b34291e8/libs/lwjgl_util_applet.jar -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Sealed: true 3 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=3aeb451f 2 | build.xml.script.CRC32=f7c14b31 3 | build.xml.stylesheet.CRC32=be360661 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=f3780c20 7 | nbproject/build-impl.xml.script.CRC32=1ce0bf5e 8 | nbproject/build-impl.xml.stylesheet.CRC32=229523de@1.38.3.45 9 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=false 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.run.all.processors=true 4 | application.title=TWL 5 | application.vendor=Matthias Mann 6 | build.classes.dir=${build.dir}/classes 7 | build.classes.excludes=**/*.java,**/*.form, **/*.orig, **/*.flex 8 | # This directory is removed when the project is cleaned: 9 | build.dir=build 10 | build.generated.dir=${build.dir}/generated 11 | build.generated.sources.dir=${build.dir}/generated-sources 12 | # Only compile against the classpath explicitly listed here: 13 | build.sysclasspath=ignore 14 | build.test.classes.dir=${build.dir}/test/classes 15 | build.test.results.dir=${build.dir}/test/results 16 | debug.classpath=\ 17 | ${run.classpath} 18 | debug.test.classpath=\ 19 | ${run.test.classpath} 20 | # This directory is removed when the project is cleaned: 21 | dist.dir=dist 22 | dist.jar=${dist.dir}/TWL.jar 23 | dist.javadoc.dir=${dist.dir}/javadoc 24 | endorsed.classpath= 25 | excludes= 26 | includes=** 27 | jar.compress=true 28 | javac.classpath=\ 29 | ${libs.MXP1.classpath}:\ 30 | ${libs.LWJGL.classpath} 31 | # Space-separated list of extra javac options 32 | javac.compilerargs=-Xlint:rawtypes -Xlint:unchecked 33 | javac.deprecation=true 34 | javac.processorpath=\ 35 | ${javac.classpath} 36 | javac.source=1.5 37 | javac.target=1.5 38 | javac.test.classpath=\ 39 | ${javac.classpath}:\ 40 | ${build.classes.dir}:\ 41 | ${libs.junit_4.classpath} 42 | javadoc.additionalparam= 43 | javadoc.author=false 44 | javadoc.encoding=${source.encoding} 45 | javadoc.noindex=false 46 | javadoc.nonavbar=false 47 | javadoc.notree=false 48 | javadoc.private=false 49 | javadoc.splitindex=true 50 | javadoc.use=true 51 | javadoc.version=false 52 | javadoc.windowtitle= 53 | jaxbwiz.endorsed.dirs="${netbeans.home}/../ide12/modules/ext/jaxb/api" 54 | manifest.file=manifest.mf 55 | meta.inf.dir=${src.dir}/META-INF 56 | platform.active=JDK_1.5 57 | run.classpath=\ 58 | ${javac.classpath}:\ 59 | ${build.classes.dir} 60 | run.jvmargs=-ea 61 | run.test.classpath=\ 62 | ${javac.test.classpath}:\ 63 | ${build.test.classes.dir} 64 | source.encoding=UTF-8 65 | src.src.dir=src 66 | test.test.dir=test 67 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | TWL 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /pom.xml_inactive: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | de.matthiasmann 5 | twl 6 | jar 7 | TWL 8 | 1.0 9 | Themable Widget Library 10 | http://twl.l33tlabs.org/ 11 | 12 | 13 | 14 | org.lwjgl.lwjgl 15 | lwjgl 16 | 2.8.5 17 | 18 | 19 | xpp3 20 | xpp3 21 | 1.1.4c 22 | 23 | 24 | 25 | 26 | UTF-8 27 | 28 | 29 | 30 | src 31 | 32 | 33 | src 34 | 35 | **/*.java 36 | **/*.flex 37 | 38 | false 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 2.3.2 46 | 47 | UTF-8 48 | 1.5 49 | 1.5 50 | 56 | 57 | 58 | 59 | 61 | org.codehaus.mojo 62 | animal-sniffer-maven-plugin 63 | 1.7 64 | 65 | 66 | org.codehaus.mojo.signature 67 | java15 68 | 1.0 69 | 70 | 71 | 72 | 73 | process-classes 74 | 75 | check 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /src-beans/de/matthiasmann/twl/input/LWJGLInput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.input.lwjgl; 31 | 32 | import de.matthiasmann.twl.GUI; 33 | import de.matthiasmann.twl.input.Input; 34 | 35 | /** 36 | * Null input handling for TWL-android.jar 37 | * 38 | * This class will be renamed to de.matthiasmann.twl.input.NullInput by build.xml 39 | * 40 | * @author Matthias Mann 41 | */ 42 | public class LWJGLInput implements Input { 43 | 44 | public LWJGLInput() { 45 | } 46 | 47 | public boolean pollInput(GUI gui) { 48 | return true; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src-beans/java/beans/PropertyChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package java.beans; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public class PropertyChangeEvent { 37 | 38 | private final Object source; 39 | private final String propertyName; 40 | private final Object oldValue; 41 | private final Object newValue; 42 | 43 | public PropertyChangeEvent(Object source, String propertyName, Object oldValue, Object newValue) { 44 | this.source = source; 45 | this.propertyName = propertyName; 46 | this.oldValue = oldValue; 47 | this.newValue = newValue; 48 | } 49 | 50 | public Object getSource() { 51 | return source; 52 | } 53 | 54 | public String getPropertyName() { 55 | return propertyName; 56 | } 57 | 58 | public Object getOldValue() { 59 | return oldValue; 60 | } 61 | 62 | public Object getNewValue() { 63 | return newValue; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src-beans/java/beans/PropertyChangeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package java.beans; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public interface PropertyChangeListener { 37 | 38 | public void propertyChange(PropertyChangeEvent event); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/CallbackWithReason.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * A callback interface with an enum as reason 34 | * 35 | * @param The type of the reason enum 36 | * @author Matthias Mann 37 | */ 38 | public interface CallbackWithReason> { 39 | 40 | public void callback(T reason); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/Clipboard.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 200-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | import java.awt.Toolkit; 33 | import java.awt.datatransfer.DataFlavor; 34 | import java.awt.datatransfer.StringSelection; 35 | import java.awt.datatransfer.Transferable; 36 | 37 | /** 38 | * A utility class to transfer text to/from the system clipboard. It uses AWT. 39 | * 40 | * @author Matthias Mann 41 | * @see Toolkit#getSystemClipboard() 42 | */ 43 | public final class Clipboard { 44 | 45 | private Clipboard() { 46 | } 47 | 48 | public static String getClipboard() { 49 | try { 50 | java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 51 | Transferable transferable = clipboard.getContents(null); 52 | if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) { 53 | return (String)transferable.getTransferData(DataFlavor.stringFlavor); 54 | } 55 | } catch (Exception ex) { 56 | ex.printStackTrace(); 57 | } 58 | return ""; 59 | } 60 | 61 | public static void setClipboard(String str) { 62 | try { 63 | java.awt.datatransfer.Clipboard clipboard = 64 | Toolkit.getDefaultToolkit().getSystemClipboard(); 65 | StringSelection transferable = new StringSelection(str); 66 | clipboard.setContents(transferable, transferable); 67 | } catch (Exception ex) { 68 | ex.printStackTrace(); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/Container.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * Can contain a single Widget and uses {@link Widget#layoutChildrenFullInnerArea() } 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class Container extends Widget { 38 | 39 | @Override 40 | public int getMinWidth() { 41 | return Math.max(super.getMinWidth(), getBorderHorizontal() + 42 | BoxLayout.computeMinWidthVertical(this)); 43 | } 44 | 45 | @Override 46 | public int getMinHeight() { 47 | return Math.max(super.getMinHeight(), getBorderVertical() + 48 | BoxLayout.computeMinHeightHorizontal(this)); 49 | } 50 | 51 | @Override 52 | public int getPreferredInnerWidth() { 53 | return BoxLayout.computePreferredWidthVertical(this); 54 | } 55 | 56 | @Override 57 | public int getPreferredInnerHeight() { 58 | return BoxLayout.computePreferredHeightHorizontal(this); 59 | } 60 | 61 | @Override 62 | protected void layout() { 63 | layoutChildrenFullInnerArea(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/Dimension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public class Dimension { 37 | 38 | public static final Dimension ZERO = new Dimension(0, 0); 39 | 40 | private final int x; 41 | private final int y; 42 | 43 | public Dimension(int x, int y) { 44 | this.x = x; 45 | this.y = y; 46 | } 47 | 48 | public int getX() { 49 | return x; 50 | } 51 | 52 | public int getY() { 53 | return y; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object obj) { 58 | if(obj == null || getClass() != obj.getClass()) { 59 | return false; 60 | } 61 | final Dimension other = (Dimension)obj; 62 | return (this.x == other.x) && (this.y == other.y); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int hash = 3; 68 | hash = 71 * hash + this.x; 69 | hash = 71 * hash + this.y; 70 | return hash; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return "Dimension[x="+x+", y="+y+"]"; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/FocusGainedCause.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * The cause for the {@link Widget#keyboardFocusGained(de.matthiasmann.twl.FocusGainedCause, de.matthiasmann.twl.Widget) } 34 | * event. 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public enum FocusGainedCause { 39 | /** 40 | * Focus transfer caused by focus key (eg TAB) 41 | */ 42 | FOCUS_KEY, 43 | /** 44 | * Focus transfer caused by mouse down event on the widget 45 | */ 46 | MOUSE_BTNDOWN, 47 | /** 48 | * A child widget requested focus 49 | */ 50 | CHILD_FOCUSED, 51 | /** 52 | * {@link Widget#requestKeyboardFocus() } was invoked 53 | */ 54 | MANUAL 55 | } 56 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/HAlignment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * Horizontal text alignment within a line. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public enum HAlignment { 38 | 39 | LEFT, CENTER, RIGHT 40 | } 41 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/ListBoxDisplay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * A interface which needs to be implemented by Widget subclasses to be 34 | * used as cells in a Listbox 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface ListBoxDisplay { 39 | 40 | public boolean isSelected(); 41 | 42 | public void setSelected(boolean selected); 43 | 44 | public boolean isFocused(); 45 | 46 | public void setFocused(boolean focused); 47 | 48 | public void setData(Object data); 49 | 50 | public void setTooltipContent(Object content); 51 | 52 | public Widget getWidget(); 53 | 54 | public void addListBoxCallback(CallbackWithReason cb); 55 | 56 | public void removeListBoxCallback(CallbackWithReason cb); 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/MenuAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public class MenuAction extends MenuElement { 37 | 38 | private Runnable cb; 39 | 40 | public MenuAction() { 41 | } 42 | 43 | public MenuAction(Runnable cb) { 44 | this.cb = cb; 45 | } 46 | 47 | /** 48 | * Creates a menu action which displays the given name and invokes the 49 | * specified callback when activated. 50 | * 51 | * @param name the name/text of the menu action 52 | * @param cb the callback to invoke 53 | * @see #setCallback(java.lang.Runnable) 54 | */ 55 | public MenuAction(String name, Runnable cb) { 56 | super(name); 57 | this.cb = cb; 58 | } 59 | 60 | public Runnable getCallback() { 61 | return cb; 62 | } 63 | 64 | /** 65 | * Sets the callback to invoke when the menu action is triggered. 66 | * 67 | *

this callback is invoked after the menu is closed.

68 | * 69 | * @param cb the callback (can be null) 70 | */ 71 | public void setCallback(Runnable cb) { 72 | this.cb = cb; 73 | } 74 | 75 | @Override 76 | protected Widget createMenuWidget(MenuManager mm, int level) { 77 | Button b = new MenuBtn(); 78 | setWidgetTheme(b, "button"); 79 | 80 | b.addCallback(mm.getCloseCallback()); 81 | 82 | if(cb != null) { 83 | b.addCallback(cb); 84 | } 85 | 86 | return b; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/MenuCheckbox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | import de.matthiasmann.twl.model.BooleanModel; 33 | import de.matthiasmann.twl.model.ToggleButtonModel; 34 | import java.beans.PropertyChangeEvent; 35 | 36 | /** 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public class MenuCheckbox extends MenuElement { 41 | 42 | private BooleanModel model; 43 | 44 | public MenuCheckbox() { 45 | } 46 | 47 | public MenuCheckbox(BooleanModel model) { 48 | this.model = model; 49 | } 50 | 51 | public MenuCheckbox(String name, BooleanModel model) { 52 | super(name); 53 | this.model = model; 54 | } 55 | 56 | public BooleanModel getModel() { 57 | return model; 58 | } 59 | 60 | public void setModel(BooleanModel model) { 61 | BooleanModel oldModel = this.model; 62 | this.model = model; 63 | firePropertyChange("model", oldModel, model); 64 | } 65 | 66 | @Override 67 | protected Widget createMenuWidget(MenuManager mm, int level) { 68 | MenuBtn btn = new MenuBtn() { 69 | @Override 70 | public void propertyChange(PropertyChangeEvent evt) { 71 | super.propertyChange(evt); 72 | ((ToggleButtonModel)getModel()).setModel(MenuCheckbox.this.getModel()); 73 | } 74 | }; 75 | btn.setModel(new ToggleButtonModel(getModel())); 76 | setWidgetTheme(btn, "checkbox"); 77 | btn.addCallback(mm.getCloseCallback()); 78 | return btn; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/MenuSpacer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public class MenuSpacer extends MenuElement { 37 | 38 | @Override 39 | protected Widget createMenuWidget(MenuManager mm, int level) { 40 | Widget w = new Widget(); 41 | setWidgetTheme(w, "spacer"); 42 | return w; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/MouseSensitiveRectangle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * A rectangle that can sense the mouse :) 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public abstract class MouseSensitiveRectangle extends Rect { 38 | 39 | public MouseSensitiveRectangle() { 40 | } 41 | 42 | /** 43 | * Test if the mouse is over this area 44 | * @return true if the mouse is over this area. 45 | */ 46 | public abstract boolean isMouseOver(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/TableSelectionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | import de.matthiasmann.twl.model.TableSelectionModel; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface TableSelectionManager { 39 | 40 | public enum SelectionGranularity { 41 | ROWS, 42 | CELLS 43 | } 44 | 45 | public TableSelectionModel getSelectionModel(); 46 | 47 | public void setAssociatedTable(TableBase base); 48 | 49 | public SelectionGranularity getSelectionGranularity(); 50 | 51 | public boolean handleKeyStrokeAction(String action, Event event); 52 | 53 | public boolean handleMouseEvent(int row, int column, Event event); 54 | 55 | public boolean isRowSelected(int row); 56 | 57 | public boolean isCellSelected(int row, int column); 58 | 59 | public int getLeadRow(); 60 | 61 | public int getLeadColumn(); 62 | 63 | public void modelChanged(); 64 | 65 | public void rowsInserted(int index, int count); 66 | 67 | public void rowsDeleted(int index, int count); 68 | 69 | public void columnInserted(int index, int count); 70 | 71 | public void columnsDeleted(int index, int count); 72 | } 73 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/ThemeInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | /** 33 | * The theme info class contains all theme specific information for a given widget. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface ThemeInfo extends ParameterMap { 38 | 39 | public ThemeInfo getChildTheme(String theme); 40 | 41 | public String getThemePath(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/ToggleButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2013, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl; 31 | 32 | import de.matthiasmann.twl.model.BooleanModel; 33 | import de.matthiasmann.twl.model.EnumModel; 34 | import de.matthiasmann.twl.model.IntegerModel; 35 | import de.matthiasmann.twl.model.OptionBooleanModel; 36 | import de.matthiasmann.twl.model.OptionEnumModel; 37 | import de.matthiasmann.twl.model.ToggleButtonModel; 38 | 39 | /** 40 | * A toggle button. 41 | * 42 | *

This class extends Button with the ablity to bind the selected state 43 | * to a {@link BooleanModel}.

44 | * 45 | *

The prefert way to use this class is by using the callback on the 46 | * {@code BooleanModel}.

47 | * 48 | *

To implement radio buttons one of the option models can be used:

    49 | *
  • {@link OptionBooleanModel} which is backed by an {@link IntegerModel}
  • 50 | *
  • {@link OptionEnumModel} which is backed by an {@link EnumModel}
  • 51 | *

52 | * 53 | * @author Matthias Mann 54 | */ 55 | public class ToggleButton extends Button { 56 | 57 | public ToggleButton() { 58 | super(new ToggleButtonModel()); 59 | } 60 | 61 | public ToggleButton(BooleanModel model) { 62 | super(new ToggleButtonModel(model)); 63 | } 64 | 65 | public ToggleButton(String text) { 66 | this(); 67 | setText(text); 68 | } 69 | 70 | public void setModel(BooleanModel model) { 71 | ((ToggleButtonModel)getModel()).setModel(model); 72 | } 73 | 74 | public boolean isActive() { 75 | return getModel().isSelected(); 76 | } 77 | 78 | public void setActive(boolean active) { 79 | getModel().setSelected(active); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/input/Input.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.input; 31 | 32 | import de.matthiasmann.twl.GUI; 33 | 34 | /** 35 | * Abstracted input polling. 36 | * Allows to use {@link GUI#update() } with generic polled input devices. 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public interface Input { 41 | 42 | /** 43 | * Poll input events. 44 | * 45 | * @param gui the GUI object which should receive the input 46 | * @return true if input events have been processed, false if the input system is currently inactive. 47 | * 48 | * @see GUI#handleKey(int, char, boolean) 49 | * @see GUI#handleMouse(int, int, int, boolean) 50 | * @see GUI#handleMouseWheel(int) 51 | */ 52 | public boolean pollInput(GUI gui); 53 | } 54 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/input/lwjgl/LWJGLInput.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.input.lwjgl; 31 | 32 | import de.matthiasmann.twl.GUI; 33 | import de.matthiasmann.twl.input.Input; 34 | import org.lwjgl.input.Keyboard; 35 | import org.lwjgl.input.Mouse; 36 | import org.lwjgl.opengl.Display; 37 | 38 | /** 39 | * Input handling based on LWJGL's Mouse & Keyboard classes. 40 | * 41 | * @author Matthias Mann 42 | */ 43 | public class LWJGLInput implements Input { 44 | 45 | private boolean wasActive; 46 | 47 | public boolean pollInput(GUI gui) { 48 | boolean active = Display.isActive(); 49 | if(wasActive && !active) { 50 | wasActive = false; 51 | return false; 52 | } 53 | wasActive = active; 54 | 55 | if(Keyboard.isCreated()) { 56 | while(Keyboard.next()) { 57 | gui.handleKey( 58 | Keyboard.getEventKey(), 59 | Keyboard.getEventCharacter(), 60 | Keyboard.getEventKeyState()); 61 | } 62 | } 63 | if(Mouse.isCreated()) { 64 | while(Mouse.next()) { 65 | gui.handleMouse( 66 | Mouse.getEventX(), gui.getHeight() - Mouse.getEventY() - 1, 67 | Mouse.getEventButton(), Mouse.getEventButtonState()); 68 | 69 | int wheelDelta = Mouse.getEventDWheel(); 70 | if(wheelDelta != 0) { 71 | gui.handleMouseWheel(wheelDelta / 120); 72 | } 73 | } 74 | } 75 | return true; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/license.html: -------------------------------------------------------------------------------- 1 | 2 | TWL logo 3 |

Copyright (c) 2008-2012, Matthias Mann

4 |

All rights reserved.

5 |

Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met:

7 |
    8 |
  • Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer.
  • 10 |
  • Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution.
  • 13 |
  • Neither the name of Matthias Mann nor the names of its contributors may 14 | be used to endorse or promote products derived from this software 15 | without specific prior written permission.
  • 16 |
  • Redistributions in source or binary form must keep the original package 17 | and class name.
  • 18 |
19 |

20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

31 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2012, Matthias Mann 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of Matthias Mann nor the names of its contributors may 14 | be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | * Redistributions in source or binary form must keep the original package 17 | and class name. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractColorSpace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * An abstract class to make implementing color spaces a bit easier 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public abstract class AbstractColorSpace implements ColorSpace { 38 | 39 | private final String colorSpaceName; 40 | private final String[] names; 41 | 42 | public AbstractColorSpace(String colorSpaceName, String ... names) { 43 | this.colorSpaceName = colorSpaceName; 44 | this.names = names; 45 | } 46 | 47 | public String getComponentName(int component) { 48 | return names[component]; 49 | } 50 | 51 | public String getColorSpaceName() { 52 | return colorSpaceName; 53 | } 54 | 55 | public int getNumComponents() { 56 | return names.length; 57 | } 58 | 59 | public float getMinValue(int component) { 60 | return 0f; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractEnumModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * Abstract base class to simplify implementing EnumModels. 34 | * 35 | * @param The enum type 36 | * @author Matthias Mann 37 | */ 38 | public abstract class AbstractEnumModel> extends HasCallback implements EnumModel { 39 | 40 | private final Class enumClass; 41 | 42 | protected AbstractEnumModel(Class clazz) { 43 | if(clazz == null) { 44 | throw new NullPointerException("clazz"); 45 | } 46 | this.enumClass = clazz; 47 | } 48 | 49 | public Class getEnumClass() { 50 | return enumClass; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractFloatModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * Abstract base class to simplify float models. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public abstract class AbstractFloatModel extends HasCallback implements FloatModel { 38 | 39 | protected AbstractFloatModel() { 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractIntegerModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * Abstract base class to simplify integerModels. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public abstract class AbstractIntegerModel extends HasCallback implements IntegerModel { 38 | 39 | protected AbstractIntegerModel() { 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.CallbackSupport; 33 | 34 | /** 35 | * An abstract base class for Properties. Provides callback handling. 36 | * 37 | * @param The type of the property value 38 | * @author Matthias Mann 39 | */ 40 | public abstract class AbstractProperty implements Property { 41 | 42 | private Runnable[] valueChangedCallbacks; 43 | 44 | public void addValueChangedCallback(Runnable cb) { 45 | valueChangedCallbacks = CallbackSupport.addCallbackToList( 46 | valueChangedCallbacks, cb, Runnable.class); 47 | } 48 | 49 | public void removeValueChangedCallback(Runnable cb) { 50 | valueChangedCallbacks = CallbackSupport.removeCallbackFromList( 51 | valueChangedCallbacks, cb); 52 | } 53 | 54 | public boolean hasValueChangedCallbacks() { 55 | return valueChangedCallbacks != null; 56 | } 57 | 58 | protected void fireValueChangedCallback() { 59 | CallbackSupport.fireCallbacks(valueChangedCallbacks); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AbstractTableColumnHeaderModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.renderer.AnimationState.StateKey; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public abstract class AbstractTableColumnHeaderModel implements TableColumnHeaderModel { 39 | 40 | private static final StateKey[] EMPTY_STATE_ARRAY = {}; 41 | 42 | public StateKey[] getColumnHeaderStates() { 43 | return EMPTY_STATE_ARRAY; 44 | } 45 | 46 | public boolean getColumnHeaderState(int column, int stateIdx) { 47 | return false; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/AutoCompletionDataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * An auto completion data source 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface AutoCompletionDataSource { 38 | 39 | /** 40 | * Collects auto completion results 41 | * 42 | * @param text The new text for which to compute auto completion 43 | * @param cursorPos The cursor position for which to compute the auto completion 44 | * @param prev The previous AutoCompletionResult - can be used to speed up the computation 45 | * @return The AutoCompletionResult object or null if no reults could be found 46 | */ 47 | public AutoCompletionResult collectSuggestions(String text, int cursorPos, AutoCompletionResult prev); 48 | } 49 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/BooleanModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.WithRunnableCallback; 33 | 34 | /** 35 | * A generic boolean model. 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface BooleanModel extends WithRunnableCallback { 40 | 41 | public boolean getValue(); 42 | 43 | public void setValue(boolean value); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/ButtonModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A generic button model. 34 | * Allows to separate button behavior from the button Widget. 35 | * 36 | * A ButtonModel should not be shared between Button instances. 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public interface ButtonModel { 41 | 42 | public boolean isSelected(); 43 | 44 | public boolean isPressed(); 45 | 46 | public boolean isArmed(); 47 | 48 | public boolean isHover(); 49 | 50 | public boolean isEnabled(); 51 | 52 | public void setSelected(boolean selected); 53 | 54 | public void setPressed(boolean pressed); 55 | 56 | public void setArmed(boolean armed); 57 | 58 | public void setHover(boolean hover); 59 | 60 | public void setEnabled(boolean enabled); 61 | 62 | public void addActionCallback(Runnable callback); 63 | 64 | public void removeActionCallback(Runnable callback); 65 | 66 | public void fireActionCallback(); 67 | 68 | public boolean hasActionCallbacks(); 69 | 70 | public void addStateCallback(Runnable callback); 71 | 72 | public void removeStateCallback(Runnable callback); 73 | 74 | /** 75 | * Called when the Button is placed in the GUI tree. 76 | * Callbacks to other models should only be installed after this call. 77 | */ 78 | public void connect(); 79 | 80 | /** 81 | * Called when the Button is no longer part of the GUI tree. 82 | * Callbacks to other models should be removed. 83 | */ 84 | public void disconnect(); 85 | } 86 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/ColorModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.Color; 33 | import de.matthiasmann.twl.utils.WithRunnableCallback; 34 | 35 | /** 36 | * A model which stores a color value. 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public interface ColorModel extends WithRunnableCallback { 41 | 42 | public Color getValue(); 43 | 44 | public void setValue(Color value); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/DateModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.WithRunnableCallback; 33 | 34 | /** 35 | * A date model which stores the current date in milliseconds 36 | * 37 | * @author Matthias Mann 38 | * @see System#currentTimeMillis() 39 | */ 40 | public interface DateModel extends WithRunnableCallback { 41 | 42 | public long getValue(); 43 | 44 | public void setValue(long date); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/EnumListModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A read only list model containing all enum values of the specified enum. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class EnumListModel> extends SimpleListModel { 38 | 39 | private final Class enumClass; 40 | private final T[] enumValues; 41 | 42 | public EnumListModel(Class enumClass) { 43 | if(!enumClass.isEnum()) { 44 | throw new IllegalArgumentException("not an enum class"); 45 | } 46 | this.enumClass = enumClass; 47 | this.enumValues = enumClass.getEnumConstants(); 48 | } 49 | 50 | public Class getEnumClass() { 51 | return enumClass; 52 | } 53 | 54 | public T getEntry(int index) { 55 | return enumValues[index]; 56 | } 57 | 58 | public int getNumEntries() { 59 | return enumValues.length; 60 | } 61 | 62 | public int findEntry(T value) { 63 | for(int i=0,n=enumValues.length ; i The enum type 38 | * @author Matthias Mann 39 | */ 40 | public interface EnumModel> extends WithRunnableCallback { 41 | 42 | public Class getEnumClass(); 43 | 44 | public T getValue(); 45 | 46 | public void setValue(T value); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/FloatModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.WithRunnableCallback; 33 | 34 | /** 35 | * A generic model for float values. 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface FloatModel extends WithRunnableCallback { 40 | 41 | public float getValue(); 42 | 43 | public float getMinValue(); 44 | 45 | public float getMaxValue(); 46 | 47 | public void setValue(float value); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/GraphLineModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A generic line model for a graph. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface GraphLineModel { 38 | 39 | /** 40 | * Returns the name of the visual style. 41 | * The style will be looked up in the theme data of the graph widget. 42 | * @return the name of the visual style. 43 | */ 44 | public String getVisualStyleName(); 45 | 46 | /** 47 | * Returns the number of points on the lines. 48 | * A line is only drawn if atleast one point is available. 49 | * @return the number of points on the lines 50 | */ 51 | public int getNumPoints(); 52 | 53 | /** 54 | * Returns the value of the desired point. 55 | * @param idx The index of the point. Will be >= 0 and < getNumPoints() 56 | * @return the value of the desired point. 57 | * @see #getNumPoints() 58 | */ 59 | public float getPoint(int idx); 60 | 61 | /** 62 | * Returns the smallest value which should be used to scale the graph. 63 | * @return the smallest value which should be used to scale the graph 64 | */ 65 | public float getMinValue(); 66 | 67 | /** 68 | * Returns the largest value which should be used to scale the graph. 69 | * @return the largest value which should be used to scale the graph 70 | */ 71 | public float getMaxValue(); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/GraphModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A generic graph data model. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface GraphModel { 38 | 39 | /** 40 | * Returns the number of lines in this graph. 41 | * @return the number of lines in this graph 42 | */ 43 | public int getNumLines(); 44 | 45 | /** 46 | * Returns the specified line model. 47 | * @param idx The line index. Must be >= 0 and < getNumLines() 48 | * @return the specified line model 49 | */ 50 | public GraphLineModel getLine(int idx); 51 | 52 | /** 53 | * The Y axis of the graph is based on min/max values. 54 | * The scaling for an axis can be compute from the combined 55 | * min/max values or using it's own min/max value. 56 | * 57 | * The combined min values is the smallest min value of all lines. 58 | * The combined max values is the largest max value of all lines. 59 | * 60 | * @return true if the Y scale is independant or false if it is combined. 61 | */ 62 | public boolean getScaleLinesIndependant(); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/IntegerModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.WithRunnableCallback; 33 | 34 | /** 35 | * A generic model for integer values. 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface IntegerModel extends WithRunnableCallback { 40 | 41 | public int getValue(); 42 | 43 | public int getMinValue(); 44 | 45 | public int getMaxValue(); 46 | 47 | public void setValue(int value); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/ListSelectionModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * Represents the selection of a list box or combo box. 34 | * 35 | * Implementation should not register callbacks on the list model. 36 | * 37 | * @param the data type of the list model 38 | * @author Matthias Mann 39 | */ 40 | public interface ListSelectionModel extends IntegerModel { 41 | 42 | /** 43 | * The index when nothing is selected 44 | */ 45 | public static final int NO_SELECTION = -1; 46 | 47 | public ListModel getListModel(); 48 | 49 | /** 50 | * Returns the selected entry in the list or null if nothing is selected. 51 | * @return the selected entry or null. 52 | */ 53 | public T getSelectedEntry(); 54 | 55 | /** 56 | * Selects the specified entry or nothing if the entry was not found. 57 | * 58 | * This method behaves like {@code setSelectedEntry(entry, NO_SELECTION)} 59 | * 60 | * @param entry the entry to select - can be null. 61 | * @return true if the entry was found 62 | * @see #setSelectedEntry(java.lang.Object, int) 63 | * @see #NO_SELECTION 64 | */ 65 | public boolean setSelectedEntry(T entry); 66 | 67 | /** 68 | * Selects the specified entry or the default index if the entry was not found 69 | * @param entry the entry to select - can be null. 70 | * @param defaultIndex the index to select when the entry was not found 71 | * @return true if the entry was found 72 | * @see #NO_SELECTION 73 | */ 74 | public boolean setSelectedEntry(T entry, int defaultIndex); 75 | } 76 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/MRUListModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A generic MRU (most recently used) list model. 34 | * 35 | * @param the data type stored in this MRU model 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface MRUListModel extends ListModel { 40 | 41 | /** 42 | * Returns the maximum number of entries stored in this MRU list 43 | * @return the maximum number of entries stored in this MRU list 44 | */ 45 | public int getMaxEntries(); 46 | 47 | public int getNumEntries(); 48 | 49 | public T getEntry(int index); 50 | 51 | /** 52 | * Adds an entry to this MRU model. If the entry is already in the MRU list, 53 | * then it is moved to the from. 54 | * 55 | * @see java.lang.Object#equals(java.lang.Object) 56 | * 57 | * @param entry the entry 58 | */ 59 | public void addEntry(T entry); 60 | 61 | /** 62 | * Removes the entry at the given index 63 | * 64 | * @param index 65 | */ 66 | public void removeEntry(int index); 67 | 68 | public void addChangeListener(ListModel.ChangeListener listener); 69 | 70 | public void removeChangeListener(ListModel.ChangeListener listener); 71 | } 72 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/ObservableCharSequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A {@link CharSequence} with change callback support. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface ObservableCharSequence extends CharSequence { 38 | 39 | public interface Callback { 40 | /** 41 | * The sequence has been modified. 42 | * @param start the start offset of the change 43 | * @param oldCount the number of characters which have been replaced 44 | * @param newCount the number of new characters inserted 45 | */ 46 | public void charactersChanged(int start, int oldCount, int newCount); 47 | } 48 | 49 | public void addCallback(Callback callback); 50 | 51 | public void removeCallback(Callback callback); 52 | } 53 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/PersistentBooleanModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import java.util.prefs.Preferences; 33 | 34 | /** 35 | * A model that stores a boolean value and supports callback on value change. 36 | * The value can also be persisted using java.util.prefs.Preferences 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public class PersistentBooleanModel extends HasCallback implements BooleanModel { 41 | 42 | private final Preferences prefs; 43 | private final String prefKey; 44 | 45 | private boolean value; 46 | 47 | public PersistentBooleanModel(Preferences prefs, String prefKey, boolean defaultValue) { 48 | if(prefs == null) { 49 | throw new NullPointerException("prefs"); 50 | } 51 | if(prefKey == null) { 52 | throw new NullPointerException("prefKey"); 53 | } 54 | this.prefs = prefs; 55 | this.prefKey = prefKey; 56 | value = prefs.getBoolean(prefKey, defaultValue); 57 | } 58 | 59 | public boolean getValue() { 60 | return value; 61 | } 62 | 63 | public void setValue(boolean value) { 64 | if(this.value != value) { 65 | this.value = value; 66 | storeSettings(); 67 | doCallback(); 68 | } 69 | } 70 | 71 | private void storeSettings() { 72 | prefs.putBoolean(prefKey, value); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/PersistentStringModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import java.util.prefs.Preferences; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public class PersistentStringModel extends HasCallback implements StringModel { 39 | 40 | private final Preferences prefs; 41 | private final String prefKey; 42 | private String value; 43 | 44 | public PersistentStringModel(Preferences prefs, String prefKey, String defaultValue) { 45 | if(prefs == null) { 46 | throw new NullPointerException("prefs"); 47 | } 48 | if(prefKey == null) { 49 | throw new NullPointerException("prefKey"); 50 | } 51 | if(defaultValue == null) { 52 | throw new NullPointerException("defaultValue"); 53 | } 54 | this.prefs = prefs; 55 | this.prefKey = prefKey; 56 | this.value = prefs.get(prefKey, defaultValue); 57 | } 58 | 59 | public String getValue() { 60 | return value; 61 | } 62 | 63 | public void setValue(String value) { 64 | if(value == null) { 65 | throw new NullPointerException("value"); 66 | } 67 | if(!this.value.equals(value)) { 68 | this.value = value; 69 | prefs.put(prefKey, value); 70 | doCallback(); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/PropertyList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * This interface is used to create sub properties in a PropertySheet if 34 | * it is used as value of another Property 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface PropertyList { 39 | 40 | public int getNumProperties(); 41 | 42 | public Property getProperty(int idx); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleAutoCompletionResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import java.util.Collection; 33 | 34 | /** 35 | * A simple auto completion result container which stores the results as strings 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public class SimpleAutoCompletionResult extends AutoCompletionResult { 40 | private final String[] results; 41 | 42 | public SimpleAutoCompletionResult(String text, int prefixLength, Collection results) { 43 | super(text, prefixLength); 44 | this.results = results.toArray(new String[results.size()]); 45 | } 46 | 47 | public SimpleAutoCompletionResult(String text, int prefixLength, String ... results) { 48 | super(text, prefixLength); 49 | this.results = results.clone(); 50 | } 51 | 52 | @Override 53 | public int getNumResults() { 54 | return results.length; 55 | } 56 | 57 | @Override 58 | public String getResult(int idx) { 59 | return results[idx]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleBooleanModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A simple boolean model 34 | * @author Matthias Mann 35 | */ 36 | public class SimpleBooleanModel extends HasCallback implements BooleanModel { 37 | 38 | private boolean value; 39 | 40 | public SimpleBooleanModel() { 41 | this(false); 42 | } 43 | 44 | public SimpleBooleanModel(boolean value) { 45 | this.value = value; 46 | } 47 | 48 | public boolean getValue() { 49 | return value; 50 | } 51 | 52 | public void setValue(boolean value) { 53 | if(this.value != value) { 54 | this.value = value; 55 | doCallback(); 56 | } 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleDateModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A simple date model 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class SimpleDateModel extends HasCallback implements DateModel { 38 | 39 | private long date; 40 | 41 | /** 42 | * Initializes the date to the current system date 43 | * @see System#currentTimeMillis() 44 | */ 45 | public SimpleDateModel() { 46 | this.date = System.currentTimeMillis(); 47 | } 48 | 49 | public SimpleDateModel(long date) { 50 | this.date = date; 51 | } 52 | 53 | public long getValue() { 54 | return date; 55 | } 56 | 57 | public void setValue(long date) { 58 | if(this.date != date) { 59 | this.date = date; 60 | doCallback(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleEnumModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A simple enum model 34 | * 35 | * @param the enum class 36 | * @author Matthias Mann 37 | */ 38 | public class SimpleEnumModel> extends AbstractEnumModel { 39 | 40 | private T value; 41 | 42 | public SimpleEnumModel(Class clazz, T value) { 43 | super(clazz); 44 | if(value == null) { 45 | throw new NullPointerException("value"); 46 | } 47 | if(!clazz.isInstance(value)) { 48 | throw new IllegalArgumentException("value"); 49 | } 50 | this.value = value; 51 | } 52 | 53 | public T getValue() { 54 | return value; 55 | } 56 | 57 | public void setValue(T value) { 58 | if(!getEnumClass().isInstance(value)) { 59 | throw new IllegalArgumentException("value"); 60 | } 61 | if(this.value != value) { 62 | this.value = value; 63 | doCallback(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleIntegerModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A simple integer model. The value is not checked against the min/max values 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class SimpleIntegerModel extends HasCallback implements IntegerModel { 38 | 39 | private final int minValue; 40 | private final int maxValue; 41 | private int value; 42 | 43 | /** 44 | * Creates a new integer model with the specified min/max and initial value 45 | * 46 | * @param minValue the minimum allowed value 47 | * @param maxValue the maximum allowed value 48 | * @param value the initial value 49 | */ 50 | public SimpleIntegerModel(int minValue, int maxValue, int value) { 51 | if(maxValue < minValue) { 52 | throw new IllegalArgumentException("maxValue < minValue"); 53 | } 54 | this.minValue = minValue; 55 | this.maxValue = maxValue; 56 | this.value = value; 57 | } 58 | 59 | public int getMaxValue() { 60 | return maxValue; 61 | } 62 | 63 | public int getMinValue() { 64 | return minValue; 65 | } 66 | 67 | public int getValue() { 68 | return value; 69 | } 70 | 71 | public void setValue(int value) { 72 | if(this.value != value) { 73 | this.value = value; 74 | doCallback(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleListModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * 34 | * @param The type of the list entries 35 | * @author Matthias Mann 36 | */ 37 | public abstract class SimpleListModel extends AbstractListModel { 38 | 39 | public Object getEntryTooltip(int index) { 40 | return null; 41 | } 42 | 43 | public boolean matchPrefix(int index, String prefix) { 44 | Object entry = getEntry(index); 45 | if(entry != null) { 46 | return entry.toString().regionMatches(true, 0, prefix, 0, prefix.length()); 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SimpleStringModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * A simple string model. Doesn't support null values. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class SimpleStringModel extends HasCallback implements StringModel { 38 | 39 | private String value; 40 | 41 | public SimpleStringModel() { 42 | value = ""; 43 | } 44 | 45 | public SimpleStringModel(String value) { 46 | if(value == null) { 47 | throw new NullPointerException("value"); 48 | } 49 | this.value = value; 50 | } 51 | 52 | public String getValue() { 53 | return value; 54 | } 55 | 56 | public void setValue(String value) { 57 | if(value == null) { 58 | throw new NullPointerException("value"); 59 | } 60 | if(!this.value.equals(value)) { 61 | this.value = value; 62 | doCallback(); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/SortOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import java.util.Collections; 33 | import java.util.Comparator; 34 | 35 | /** 36 | * An enum class which represents basic sort order 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public enum SortOrder { 41 | ASCENDING { 42 | public Comparator map(Comparator c) { return c; } 43 | public SortOrder invert() { return DESCENDING; } 44 | }, 45 | DESCENDING { 46 | public Comparator map(Comparator c) { return Collections.reverseOrder(c); } 47 | public SortOrder invert() { return ASCENDING; } 48 | }; 49 | 50 | public abstract Comparator map(Comparator c); 51 | public abstract SortOrder invert(); 52 | } 53 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/StringModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | import de.matthiasmann.twl.utils.WithRunnableCallback; 33 | 34 | /** 35 | * A string data model. 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface StringModel extends WithRunnableCallback { 40 | 41 | String getValue(); 42 | 43 | void setValue(String value); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/TreeTableModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public interface TreeTableModel extends TableColumnHeaderModel, TreeTableNode { 37 | 38 | public interface ChangeListener extends ColumnHeaderChangeListener { 39 | public void nodesAdded(TreeTableNode parent, int idx, int count); 40 | 41 | public void nodesRemoved(TreeTableNode parent, int idx, int count); 42 | 43 | public void nodesChanged(TreeTableNode parent, int idx, int count); 44 | } 45 | 46 | public void addChangeListener(ChangeListener listener); 47 | 48 | public void removeChangeListener(ChangeListener listener); 49 | } 50 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/model/TreeTableNode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.model; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public interface TreeTableNode { 37 | 38 | public Object getData(int column); 39 | 40 | public Object getTooltipContent(int column); 41 | 42 | public TreeTableNode getParent(); 43 | 44 | public boolean isLeaf(); 45 | 46 | public int getNumChildren(); 47 | 48 | public TreeTableNode getChild(int idx); 49 | 50 | public int getChildIndex(TreeTableNode child); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/AttributedString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * An attribute string which also works as an iterator. 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface AttributedString extends CharSequence, AnimationState { 38 | 39 | /** 40 | * Returns the current position of the attribute iterator 41 | * @return the current position 42 | */ 43 | public int getPosition(); 44 | 45 | /** 46 | * Changes the current position. 47 | * @param pos the new position 48 | * @throws IllegalArgumentException when {@code pos} is < 0 or > length() 49 | */ 50 | public void setPosition(int pos); 51 | 52 | /** 53 | * Moves the current position forward to the next segment. 54 | * @return the new position 55 | */ 56 | public int advance(); 57 | } 58 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/AttributedStringFontCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public interface AttributedStringFontCache extends Resource { 37 | 38 | /** 39 | * Returns the width in pixels of the cached text block 40 | * @return the width in pixels of the cached text block 41 | */ 42 | public int getWidth(); 43 | 44 | /** 45 | * Returns the height in pixels of the cached text block 46 | * @return the height in pixels of the cached text block 47 | */ 48 | public int getHeight(); 49 | 50 | /** 51 | * Draw the cached text block at the given coordinates 52 | * @param x the left coordinate 53 | * @param y the top coordinate 54 | */ 55 | public void draw(int x, int y); 56 | } 57 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/CacheContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * A cache context is used by the renderer to cache images and fonts. 34 | * 35 | * When reloading a theme a new CacheContext should be used to ensure that 36 | * all images and fonts are reloaded. 37 | * 38 | * When switching between different themes the same CacheContext should be 39 | * used to prevent reloading of already loaded images and fonts. 40 | * 41 | * When a cache context is destroyed then all loaded resources may become 42 | * unavilable. 43 | * 44 | * @author Matthias Mann 45 | */ 46 | public interface CacheContext extends Resource { 47 | 48 | /** 49 | * A cache context is valid until it's destroyed. 50 | * 51 | * @return true if it is valid 52 | */ 53 | public boolean isValid(); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/Font2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * Extended font rendering API 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface Font2 extends Font { 38 | 39 | int drawText(int x, int y, AttributedString attributedString); 40 | 41 | int drawText(int x, int y, AttributedString attributedString, int start, int end); 42 | 43 | void drawMultiLineText(int x, int y, AttributedString attributedString); 44 | 45 | void drawMultiLineText(int x, int y, AttributedString attributedString, int start, int end); 46 | 47 | AttributedStringFontCache cacheText(AttributedStringFontCache prevCache, AttributedString attributedString); 48 | 49 | AttributedStringFontCache cacheText(AttributedStringFontCache prevCache, AttributedString attributedString, int start, int end); 50 | 51 | AttributedStringFontCache cacheMultiLineText(AttributedStringFontCache prevCache, AttributedString attributedString); 52 | 53 | AttributedStringFontCache cacheMultiLineText(AttributedStringFontCache prevCache, AttributedString attributedString, int start, int end); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/FontCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * A cached text block interface 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface FontCache extends Resource { 38 | 39 | /** 40 | * Returns the width in pixels of the cached text block 41 | * @return the width in pixels of the cached text block 42 | */ 43 | public int getWidth(); 44 | 45 | /** 46 | * Returns the height in pixels of the cached text block 47 | * @return the height in pixels of the cached text block 48 | */ 49 | public int getHeight(); 50 | 51 | /** 52 | * Draw the cached text block at the given coordinates with the given color 53 | * @param as A time source for animation - may be null 54 | * @param x the left coordinate 55 | * @param y the top coordinate 56 | */ 57 | public void draw(AnimationState as, int x, int y); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | import de.matthiasmann.twl.Color; 33 | 34 | /** 35 | * A image object can be used for rendering. 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface Image { 40 | 41 | /** 42 | * Returns the width in pixels of the image 43 | * @return the width in pixels of the image 44 | */ 45 | public int getWidth(); 46 | 47 | /** 48 | * Returns the height in pixels of the image 49 | * @return the height in pixels of the image 50 | */ 51 | public int getHeight(); 52 | 53 | /** 54 | * Draws the image in it's original size at the given location 55 | * @param as A time source for animation - may be null 56 | * @param x left coordinate 57 | * @param y top coordinate 58 | */ 59 | public void draw(AnimationState as, int x, int y); 60 | 61 | /** 62 | * Draws the image scaled to the given size at the given location 63 | * @param as A time source for animation - may be null 64 | * @param x left coordinate 65 | * @param y top coordinate 66 | * @param width the width in pixels 67 | * @param height the height in pixels 68 | */ 69 | public void draw(AnimationState as, int x, int y, int width, int height); 70 | 71 | /** 72 | * Creates a new image with is tinted with the specified color. 73 | * 74 | * Tinting works by multiplying the color of the image's pixels 75 | * with the specified color. 76 | * 77 | * @param color The color used for tinting. 78 | * @return a new Image object. 79 | */ 80 | public Image createTintedVersion(Color color); 81 | } 82 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/LineRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | import de.matthiasmann.twl.Color; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface LineRenderer { 39 | 40 | /** 41 | * Draws a line with the specified width and color. 42 | * Support for line width other then 1.0 is optional. 43 | * 44 | * @param pts An array of xy coordinate pairs 45 | * @param numPts Number of points to draw 46 | * @param width the line width. 47 | * @param color the Color of the line. 48 | * @param drawAsLoop true if a line should be rendered from last to first vertex. 49 | */ 50 | public void drawLine(float[] pts, int numPts, float width, Color color, boolean drawAsLoop); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/MouseCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2013, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | import de.matthiasmann.twl.GUI; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface MouseCursor { 39 | 40 | /** 41 | * An alias for the standard OS mouse cursor. 42 | * 43 | *

{@link GUI#setCursor() } will replace that with null before 44 | * calling {@link Renderer#setCursor(de.matthiasmann.twl.renderer.MouseCursor) }

45 | */ 46 | public static final MouseCursor OS_DEFAULT = new MouseCursor() {}; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/OffscreenRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | import de.matthiasmann.twl.Widget; 33 | 34 | /** 35 | * An interface to allow offscreen rendering for special effects 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public interface OffscreenRenderer { 40 | 41 | /** 42 | * Starts offscreen rendering. All following rendering operations will render 43 | * into the returned offscreen surface. Rendering outside the specified area 44 | * will be ignored. 45 | * 46 | * @param widget the widget which will render to the returned surface - can be null. 47 | * @param oldSurface the previous offscreen surface to reuse / overwrite 48 | * @param x the X coordinate of the region, can be negative. 49 | * @param y the Y coordinate of the region, can be negative. 50 | * @param width the width, can be larger then the screen size 51 | * @param height the height, can be larger then the screen size 52 | * @return the OffscreenSurface or null if offscreen rendering could not be started. 53 | */ 54 | public OffscreenSurface startOffscreenRendering(Widget widget, 55 | OffscreenSurface oldSurface, int x, int y, int width, int height); 56 | 57 | /** 58 | * Ends the current offscreen rendering. 59 | * Only call this method after a sucessful call of 60 | * {@link #startOffscreenRendering(de.matthiasmann.twl.renderer.OffscreenSurface, int, int, int, int) } 61 | */ 62 | public void endOffscreenRendering(); 63 | } 64 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/OffscreenSurface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * An offscreen surface. 34 | * 35 | *

It exposes all Image methods, in order to do special effects 36 | * you need to cast this to the implementation

. 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public interface OffscreenSurface extends Resource, Image { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/QueriablePixels.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2014, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | import de.matthiasmann.twl.Color; 33 | 34 | /** 35 | * Optional interface for {@link Image} / {@link Texture} to get access to the 36 | * pixel data 37 | * 38 | * @author Matthias Mann 39 | */ 40 | public interface QueriablePixels { 41 | 42 | /** 43 | * Returns the color value of the spicified pixel 44 | * @param x the X coordinate 45 | * @param y the Y coordinate 46 | * @return the ARGB value 47 | * @throws IllegalArgumentException when the coordinates are out of bounds 48 | * @throws UnsupportedOperationException when the internal representation does not support querying the pixel data 49 | * @see Color#toARGB() 50 | */ 51 | public int getPixelValue(int x, int y); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/Resource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * A resource is an object that needs to be destroyed when no longer in used. 34 | * @author Matthias Mann 35 | */ 36 | public interface Resource { 37 | 38 | /** 39 | * After destroying a resurce it is no longer useable. 40 | */ 41 | public void destroy(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/SupportsDrawRepeat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer; 31 | 32 | /** 33 | * Additional drawing routine for Image objects. 34 | * Will be used by RepeatImage class if the base image supports this. 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface SupportsDrawRepeat { 39 | 40 | public void draw(AnimationState as, int x, int y, int width, int height, 41 | int repeatCountX, int repeatCountY); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/lwjgl/SWCursor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2009, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer.lwjgl; 31 | 32 | import de.matthiasmann.twl.renderer.Image; 33 | import de.matthiasmann.twl.renderer.MouseCursor; 34 | import org.lwjgl.opengl.GL11; 35 | 36 | /** 37 | * 38 | * @author Matthias Mann 39 | */ 40 | class SWCursor extends TextureAreaBase implements MouseCursor { 41 | 42 | private final LWJGLTexture texture; 43 | private final int hotSpotX; 44 | private final int hotSpotY; 45 | private final Image imageRef; 46 | 47 | SWCursor(LWJGLTexture texture, int x, int y, int width, int height, int hotSpotX, int hotSpotY, Image imageRef) { 48 | super(x, y, width, height, texture.getTexWidth(), texture.getTexHeight()); 49 | this.texture = texture; 50 | this.hotSpotX = hotSpotX; 51 | this.hotSpotY = hotSpotY; 52 | this.imageRef = imageRef; 53 | } 54 | 55 | void render(int x, int y) { 56 | if(imageRef != null) { 57 | imageRef.draw(texture.renderer.swCursorAnimState, x-hotSpotX, y-hotSpotY); 58 | } else if(texture.bind()) { 59 | GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 60 | GL11.glBegin(GL11.GL_QUADS); 61 | drawQuad(x-hotSpotX, y-hotSpotY, width, height); 62 | GL11.glEnd(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/lwjgl/TextureDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2013, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer.lwjgl; 31 | 32 | import java.io.Closeable; 33 | import java.io.IOException; 34 | import java.net.URLConnection; 35 | import java.net.URLStreamHandler; 36 | import java.nio.ByteBuffer; 37 | 38 | /** 39 | * A texture decoder interface. 40 | * 41 | * Return an instance of this interface from {@see URLConnection#getContent(java.lang.Class[]) } 42 | * when queried for {@code TextureDecoder.class} 43 | * 44 | * @author Matthias Mann 45 | * @see URLStreamHandler 46 | * @see URLConnection 47 | */ 48 | public interface TextureDecoder extends Closeable { 49 | 50 | public void open() throws IOException; 51 | 52 | public int getWidth(); 53 | 54 | public int getHeight(); 55 | 56 | public LWJGLTexture.Format decideTextureFormat(LWJGLTexture.Format fmt) throws IOException; 57 | 58 | public void decode(ByteBuffer buf, int stride, LWJGLTexture.Format fmt) throws IOException; 59 | } 60 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/lwjgl/TexturePostProcessing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer.lwjgl; 31 | 32 | import java.nio.ByteBuffer; 33 | 34 | /** 35 | * 36 | * @author Matthias Mann 37 | */ 38 | public interface TexturePostProcessing { 39 | 40 | public void process(ByteBuffer buffer, int stride, int width, int height, LWJGLTexture.Format fmt); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/renderer/lwjgl/VertexArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.renderer.lwjgl; 31 | 32 | import java.nio.FloatBuffer; 33 | import org.lwjgl.BufferUtils; 34 | import org.lwjgl.opengl.GL11; 35 | 36 | /** 37 | * Simple vertex array class. 38 | * 39 | *

This class manages an interleaved vertex array in float format: {@code tx, ty, x, y}

40 | * 41 | * @author Matthias Mann 42 | */ 43 | public class VertexArray { 44 | 45 | private FloatBuffer va; 46 | 47 | public FloatBuffer allocate(int maxQuads) { 48 | int capacity = 4 * 4 * maxQuads; 49 | if(va == null || va.capacity() < capacity) { 50 | va = BufferUtils.createFloatBuffer(capacity); 51 | } 52 | va.clear(); 53 | return va; 54 | } 55 | 56 | public void bind() { 57 | va.position(2); 58 | GL11.glVertexPointer(2, 4*4, va); 59 | va.position(0); 60 | GL11.glTexCoordPointer(2, 4*4, va); 61 | GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); 62 | GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); 63 | } 64 | 65 | public void drawVertices(int start, int count) { 66 | GL11.glDrawArrays(GL11.GL_QUADS, start, count); 67 | } 68 | 69 | public void drawQuads(int start, int count) { 70 | GL11.glDrawArrays(GL11.GL_QUADS, start*4, count*4); 71 | } 72 | 73 | public void unbind() { 74 | GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); 75 | GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/textarea/BoxAttribute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.textarea; 31 | 32 | /** 33 | * A bundle of 4 attributes which form the top, left, right and bottom part of a box 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public class BoxAttribute { 38 | public final StyleAttribute top; 39 | public final StyleAttribute left; 40 | public final StyleAttribute right; 41 | public final StyleAttribute bottom; 42 | 43 | BoxAttribute(StyleAttribute top, StyleAttribute left, StyleAttribute right, StyleAttribute bottom) { 44 | this.top = top; 45 | this.left = left; 46 | this.right = right; 47 | this.bottom = bottom; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/textarea/OrderedListType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.textarea; 31 | 32 | import de.matthiasmann.twl.utils.TextUtil; 33 | 34 | /** 35 | * Number formatting for ordered lists 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public class OrderedListType { 40 | 41 | public static final OrderedListType DECIMAL = new OrderedListType(); 42 | 43 | protected final String characterList; 44 | 45 | /** 46 | * Creates a new OrderedListType which just uses {@link Integer#toString(int) } 47 | */ 48 | public OrderedListType() { 49 | this.characterList = null; 50 | } 51 | 52 | /** 53 | * Creates a new OrderedListType which uses {@link TextUtil#toCharListNumber(int, java.lang.String) } 54 | * for positive numbers and {@link Integer#toString(int) } for the rest. 55 | * 56 | * @param characterList the character list 57 | */ 58 | public OrderedListType(String characterList) { 59 | this.characterList = characterList; 60 | } 61 | 62 | /** 63 | * Convert the number into a String 64 | * @param nr the number 65 | * @return the String which represents the number 66 | */ 67 | public String format(int nr) { 68 | if(nr >= 1 && characterList != null) { 69 | return TextUtil.toCharListNumber(nr, characterList); 70 | } else { 71 | return Integer.toString(nr); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/textarea/StyleSheetResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.textarea; 31 | 32 | /** 33 | * 34 | * @author Matthias Mann 35 | */ 36 | public interface StyleSheetResolver { 37 | 38 | public void startLayout(); 39 | 40 | public Style resolve(Style style); 41 | 42 | public void layoutFinished(); 43 | } 44 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/textarea/TextDecoration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2012, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.textarea; 31 | 32 | /** 33 | * CSS text-decoration values 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public enum TextDecoration { 38 | NONE, 39 | UNDERLINE, 40 | LINE_THROUGH 41 | } 42 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/theme/ComposedImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.theme; 31 | 32 | import de.matthiasmann.twl.Border; 33 | import de.matthiasmann.twl.Color; 34 | import de.matthiasmann.twl.renderer.AnimationState; 35 | import de.matthiasmann.twl.renderer.Image; 36 | 37 | /** 38 | * A image composed by layering several images. Layer 0 is the base and drawn first. 39 | * 40 | * @author Matthias Mann 41 | */ 42 | class ComposedImage implements Image, HasBorder { 43 | 44 | private final Image[] layers; 45 | private final Border border; 46 | 47 | public ComposedImage(Image[] layers, Border border) { 48 | super(); 49 | this.layers = layers; 50 | this.border = border; 51 | } 52 | 53 | public void draw(AnimationState as, int x, int y) { 54 | draw(as, x, y, getWidth(), getHeight()); 55 | } 56 | 57 | public void draw(AnimationState as, int x, int y, int width, int height) { 58 | for(Image layer : layers) { 59 | layer.draw(as, x, y, width, height); 60 | } 61 | } 62 | 63 | public int getHeight() { 64 | return layers[0].getHeight(); 65 | } 66 | 67 | public int getWidth() { 68 | return layers[0].getWidth(); 69 | } 70 | 71 | public Border getBorder() { 72 | return border; 73 | } 74 | 75 | public Image createTintedVersion(Color color) { 76 | Image[] newLayers = new Image[layers.length]; 77 | for(int i=0 ; i remain) { 62 | len = remain; 63 | } 64 | cur.getChars(pos, pos += len, cbuf, off); 65 | return len; 66 | } 67 | 68 | @Override 69 | public void close() { 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/de/matthiasmann/twl/utils/WithRunnableCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2011, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.utils; 31 | 32 | /** 33 | * An interface to add/remove callbacks of type Runnable 34 | * 35 | * @author Matthias Mann 36 | */ 37 | public interface WithRunnableCallback { 38 | 39 | public void addCallback(Runnable cb); 40 | 41 | public void removeCallback(Runnable cb); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /test/de/matthiasmann/twl/textarea/StyleAttributeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2010, Matthias Mann 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Matthias Mann nor the names of its contributors may 15 | * be used to endorse or promote products derived from this software 16 | * without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | package de.matthiasmann.twl.textarea; 31 | 32 | import org.junit.Test; 33 | import static org.junit.Assert.*; 34 | 35 | /** 36 | * 37 | * @author Matthias Mann 38 | */ 39 | public class StyleAttributeTest { 40 | 41 | @Test 42 | public void testOrdinal() { 43 | for(int i=0 ; i