├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.jdt.core.prefs └── org.eclipse.wst.common.project.facet.core.xml ├── LICENSE ├── README.md ├── build ├── Build.java └── nobuto.jar ├── media ├── ffm_gwtswing.png └── ffm_swing.png ├── nobuto.bat ├── nobuto.sh ├── resources └── common │ ├── gwtswing_resources.gwt.xml │ └── resources │ ├── de │ └── exware │ │ └── gwtswing │ │ ├── gwtswing.css │ │ └── icons │ │ ├── cancel.png │ │ ├── download.svg │ │ ├── file.svg │ │ ├── folder.svg │ │ └── upload.svg │ └── localization │ └── de.exware.gwtswing.properties ├── source └── java │ └── de │ └── exware │ ├── gwtswing.gwt.xml │ └── gwtswing │ ├── Constants.java │ ├── DefaultStringRenderer.java │ ├── PartitionedPanel.java │ ├── StringRenderer.java │ ├── animation │ ├── AbstractAnimation.java │ ├── Animation.java │ ├── ExpandHorizontalAnimation.java │ ├── ExpandVerticalAnimation.java │ ├── FadeInAnimation.java │ ├── FadeInOutAnimation.java │ ├── FadeOutAnimation.java │ ├── TriggerEvent.java │ └── trigger │ │ ├── VisibilityOffTrigger.java │ │ ├── VisibilityOnTrigger.java │ │ └── VisibilityTrigger.java │ ├── awt │ ├── GBorderLayout.java │ ├── GCanvas.java │ ├── GCardLayout.java │ ├── GColor.java │ ├── GCursor.java │ ├── GDimension.java │ ├── GFont.java │ ├── GFontMetrics.java │ ├── GGraphics2D.java │ ├── GGridBagConstraints.java │ ├── GGridBagLayout.java │ ├── GGridBagLayoutInfo.java │ ├── GGridLayout.java │ ├── GImage.java │ ├── GInsets.java │ ├── GLayoutManager.java │ ├── GPoint.java │ ├── GRectangle.java │ ├── GShape.java │ ├── GToolkit.java │ ├── GWindow.java │ ├── event │ │ ├── GAWTEvent.java │ │ ├── GAWTEventListener.java │ │ ├── GActionEvent.java │ │ ├── GActionListener.java │ │ ├── GComponentAdapter.java │ │ ├── GComponentEvent.java │ │ ├── GComponentListener.java │ │ ├── GContainerEvent.java │ │ ├── GContainerListener.java │ │ ├── GFocusEvent.java │ │ ├── GFocusListener.java │ │ ├── GKeyAdapter.java │ │ ├── GKeyEvent.java │ │ ├── GKeyListener.java │ │ ├── GMouseAdapter.java │ │ ├── GMouseEvent.java │ │ ├── GMouseListener.java │ │ ├── GMouseMotionAdapter.java │ │ ├── GMouseMotionListener.java │ │ ├── GMouseWheelEvent.java │ │ ├── GMouseWheelListener.java │ │ ├── GTouchEvent.java │ │ └── GTouchListener.java │ └── geom │ │ ├── Ellipse2D.java │ │ ├── Rectangle2D.java │ │ └── RectangularShape.java │ ├── swing │ ├── CardPanel.java │ ├── GAbstractAction.java │ ├── GAbstractButton.java │ ├── GAbstractListModel.java │ ├── GAction.java │ ├── GButton.java │ ├── GButtonGroup.java │ ├── GCheckBox.java │ ├── GComboBox.java │ ├── GComboBoxModel.java │ ├── GComponent.java │ ├── GDefaultComboBoxModel.java │ ├── GDefaultListCellRenderer.java │ ├── GDefaultListModel.java │ ├── GDialog.java │ ├── GDialogCallback.java │ ├── GFileChooser.java │ ├── GFrame.java │ ├── GIcon.java │ ├── GImageIcon.java │ ├── GLabel.java │ ├── GList.java │ ├── GListCellRenderer.java │ ├── GListModel.java │ ├── GListSelectionModel.java │ ├── GLookAndFeel.java │ ├── GMenu.java │ ├── GMenuBar.java │ ├── GMenuItem.java │ ├── GMutableComboBoxModel.java │ ├── GOptionPane.java │ ├── GPanel.java │ ├── GPasswordField.java │ ├── GPopup.java │ ├── GPopupFactory.java │ ├── GPopupMenu.java │ ├── GProgressBar.java │ ├── GRadioButton.java │ ├── GRepaintManager.java │ ├── GScrollPane.java │ ├── GSlider.java │ ├── GSplitPane.java │ ├── GSwingConstants.java │ ├── GSwingUtilities.java │ ├── GTabbedPane.java │ ├── GTable.java │ ├── GTextArea.java │ ├── GTextComponent.java │ ├── GTextField.java │ ├── GToggleButton.java │ ├── GToolBar.java │ ├── GToolTipManager.java │ ├── GTree.java │ ├── GUIManager.java │ ├── GUtilities.java │ ├── TableFilter.java │ ├── border │ │ ├── GBevelBorder.java │ │ ├── GBorder.java │ │ ├── GBorderFactory.java │ │ ├── GEmptyBorder.java │ │ ├── GEtchedBorder.java │ │ ├── GLineBorder.java │ │ ├── GTitledBorder.java │ │ └── SelectiveLineBorder.java │ ├── event │ │ ├── DefaultGestureListener.java │ │ ├── GChangeEvent.java │ │ ├── GChangeListener.java │ │ ├── GColumnEvent.java │ │ ├── GColumnListener.java │ │ ├── GListDataEvent.java │ │ ├── GListDataListener.java │ │ ├── GListSelectionEvent.java │ │ ├── GListSelectionListener.java │ │ ├── GPropertyChangeEvent.java │ │ ├── GPropertyChangeListener.java │ │ ├── GTabAdapter.java │ │ ├── GTabEvent.java │ │ ├── GTabListener.java │ │ ├── GTableModelEvent.java │ │ ├── GTableModelListener.java │ │ ├── GTreeModelEvent.java │ │ ├── GTreeModelListener.java │ │ ├── GTreeSelectionEvent.java │ │ └── GTreeSelectionListener.java │ ├── plaf │ │ ├── ComponentUI.java │ │ └── GUIDefaults.java │ ├── table │ │ ├── GAbstractTableModel.java │ │ ├── GDefaultTableCellRenderer.java │ │ ├── GTableCellRenderer.java │ │ ├── GTableManager.java │ │ ├── GTableModel.java │ │ └── TableFilterDialog.java │ └── tree │ │ ├── GDefaultMutableTreeNode.java │ │ ├── GDefaultTreeCellRenderer.java │ │ ├── GDefaultTreeModel.java │ │ ├── GMutableTreeNode.java │ │ ├── GTreeCellRenderer.java │ │ ├── GTreeModel.java │ │ ├── GTreeNode.java │ │ └── GTreePath.java │ └── util │ └── GEventObject.java └── version.txt /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.war 15 | *.nar 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | /out/ 24 | /build/classes/ 25 | /tmp/ 26 | /dist/ -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | de.exware.gwtswing 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.wst.common.project.facet.core.nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.release=disabled 13 | org.eclipse.jdt.core.compiler.source=1.8 14 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GWTSwing 2 | This is an UI API similar to Java's Swing API, but on top of Java to Web transpilers like GWT and TeaVM. 3 | Even though, the name is still GWTSwing, it has been ported to TeaVM by introducing a platform abstraction layer named 4 | gplatform, with implementations for GWT and TeaVM. 5 | 6 | There are 2 main differences between Swing an GWTSwing. 7 | 1. Modal dialogs don't stop event execution. Instead of that, callback objects can be used, to get notified if a dialog was closed. 8 | 2. All Classnames beginn with "G" instead of "J" (GTextField instead of JTextField). This was done to avoid license problems, because the API is now different from Oracles Swing and to avoid confusion while developing with GWTSwing. 9 | 10 | One of the main benefits is, that there are no server calls after starting the application. Everything is handled locally on the client, until you do server calls by yourself. 11 | 12 | ## What's new 13 | ### 2024-12-27 Version 1.3 14 | - DefaultGestureListener will now create useful calls on Swiping, Scaling and Clicking 15 | - GPopupMenus will always be inside the visible Browser area. If the requested popup position is outside, then it is moved into the visible area. 16 | - Fixed oversized GTree 17 | - other Small fixes 18 | 19 | ### 2024-12-21 Version 1.2.1 20 | This version fixes an issue with padding on GLabels and conatins better looking Tabs as well as some other small fixes and enhancements. 21 | 22 | ### 2024-03-17 Version 1.2 23 | GWTSwing can now dynamically switch between different Stylesheets. To see that in action just have a look at the demos listed below. Inside the demo select "Look" on the left, and then press one of the available style buttons like "Dark" for the Dark Mode. 24 | 25 | ## How to use 26 | ### GWT 27 | GWTSwing is used like other gwt libraries. Just add the gwtswing, gplatform and gplatform.gwt to your classpath and 28 | 29 | ``` 30 | 31 | ``` 32 | to your projects ```abc.gwt.xml```. 33 | Additionally you should add the css file to your html pages header 34 | ``` 35 | 36 | ``` 37 | 38 | After that, you can use the GWTSwing classes in your project. 39 | 40 | ``` 41 | GPanel panel = new GPanel(); 42 | panel.setLayout(new GGridLayout(1, 1)); 43 | GLabel label = new GLabel("Hello World"); 44 | panel.add(label); 45 | panel.setSize(800,600); 46 | GUtilities.addToBody(panel); 47 | ``` 48 | Looks like Swing? Thats the goal! :-) 49 | 50 | The call of 'GUtilities.addToBody' appends your GWTSwing UI to the Web Page. 51 | 52 | Porting an existing Swing application is now nearly as easy as replacing all "J" with "G". 53 | 54 | ### TeaVM 55 | To use GWTSwing with teavm you need the contents of the following 56 | repositories: gplatform.teavm, gplatform and of course gwtswing. 57 | 58 | For each of them call 59 | 60 | ``` 61 | sh nobuto.sh -t installToMaven -vvv 62 | ``` 63 | to add them to your local maven repository. 64 | Then include the gplatform.teavm and gwtswing as dependencies in your project. 65 | 66 | ``` 67 | 68 | de.exware 69 | de.exware.gplatform.teavm 70 | 1.0 71 | 72 | 73 | de.exware 74 | de.exware.gwtswing 75 | 1.0 76 | 77 | ``` 78 | 79 | Furthermore you need to include the contents of the resources folder in the webapp folder. 80 | 81 | You have to manually link the css file with: 82 | 83 | ``` 84 | 85 | ``` 86 | Now you need to initialize the TeavmGPPlatform class with a static call to the init method. 87 | 88 | ```java 89 | public static void main(String[] args) 90 | { 91 | TeavmGPlatform.init(); 92 | ... 93 | } 94 | ``` 95 | 96 | After that you are good to go and use the G classes of gwtswing. 97 | 98 | ## Demo 99 | A small demo application, which shows some of the main UI components can be found here: 100 | 101 | with GWT: http://www.exware.de/gwtswing/demo/gwt/demo.html 102 | 103 | with TeaVM: http://www.exware.de/gwtswing/demo/teavm/demo.html 104 | 105 | ## Real live usage 106 | Where is GWTSwing used 107 | 108 | ### keedo 109 | An archive system for digital documents which allows to set markers on documents without modifying the original documents. Includes an automatic text recognition system (OCR) for scanned documents. A demo can be found on the projects homepage. https://keeitsi.com/ 110 | 111 | ### Keeitsi homepage 112 | The companies homepage was made with GWTSwing just to prove, that it is possible. 113 | 114 | ### FFManager 115 | FFManager is an application to manage volunteer fire brigades. In it's newest release 4.x the developers began to port the Swing UI to GWTSwing. 116 | This looks like 117 |
118 | 119 |
compared to the original swing application: 120 |
121 | 122 | -------------------------------------------------------------------------------- /build/Build.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.IOException; 3 | 4 | import de.exware.nobuto.java.JavaBuilder; 5 | import de.exware.nobuto.maven.Maven; 6 | import de.exware.nobuto.maven.MavenDependency; 7 | import de.exware.nobuto.utils.OperatingSystem; 8 | import de.exware.nobuto.utils.Utilities; 9 | 10 | public class Build extends JavaBuilder 11 | { 12 | private static final String PROJECTNAME = "de.exware.gwtswing"; 13 | 14 | private File jarFile = new File("dist/" + PROJECTNAME + ".jar"); 15 | private File sourceJarFile = new File("dist/" + PROJECTNAME + "-sources.jar"); 16 | 17 | public Build() throws IOException, InterruptedException 18 | { 19 | super(PROJECTNAME); 20 | Maven maven = Maven.getDefaultinstance(); 21 | if(OperatingSystem.isWindows()) 22 | { 23 | maven.addRepository("file:///" + maven.getLocalRepo() + "/"); 24 | } 25 | else 26 | { 27 | maven.addRepository("file://" + maven.getLocalRepo() + "/"); 28 | } 29 | } 30 | 31 | @Override 32 | public void dist() throws Exception 33 | { 34 | super.dist(); 35 | jarFile.getParentFile().mkdir(); 36 | jar(jarFile.getAbsolutePath(), "out", null); 37 | } 38 | 39 | public void installToMaven() throws Exception 40 | { 41 | clean(); 42 | dist(); 43 | createSourceJar(); 44 | Maven.getDefaultinstance().installJar(jarFile, "de.exware", PROJECTNAME, getVersion()); 45 | Maven.getDefaultinstance().installSourceJar(sourceJarFile, "de.exware", PROJECTNAME, getVersion()); 46 | } 47 | 48 | public void createSourceJar() throws IOException 49 | { 50 | File file = new File("tmp/sourceJar"); 51 | Utilities.delete(file, true); 52 | Utilities.copy("source/java", file, true); 53 | jar(sourceJarFile.getAbsolutePath(), file, null); 54 | } 55 | 56 | @Override 57 | public void clean() throws IOException 58 | { 59 | Utilities.delete(new File("dist")); 60 | Utilities.delete(new File("out")); 61 | Utilities.delete(new File("tmp")); 62 | new File("out").mkdir(); 63 | } 64 | 65 | @Override 66 | public void compile() throws Exception 67 | { 68 | addSources("source/java"); 69 | addDependency(new MavenDependency("de.exware", "de.exware.gplatform", "1.1")); 70 | super.compile(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /build/nobuto.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keinhaar/gwtswing/a7ee9a979c4c427544be54f22a9b2b42975483c9/build/nobuto.jar -------------------------------------------------------------------------------- /media/ffm_gwtswing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keinhaar/gwtswing/a7ee9a979c4c427544be54f22a9b2b42975483c9/media/ffm_gwtswing.png -------------------------------------------------------------------------------- /media/ffm_swing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keinhaar/gwtswing/a7ee9a979c4c427544be54f22a9b2b42975483c9/media/ffm_swing.png -------------------------------------------------------------------------------- /nobuto.bat: -------------------------------------------------------------------------------- 1 | mkdir build\classes 2 | java -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT -Djava.net.useSystemProxies=true -cp build/classes;build/nobuto.jar de.exware.nobuto.Main %1 %2 %3 %4 3 | -------------------------------------------------------------------------------- /nobuto.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir build/classes 3 | java -Djava.net.useSystemProxies=true -cp build/classes:build/nobuto.jar de.exware.nobuto.Main $1 $2 $3 $4 4 | 5 | -------------------------------------------------------------------------------- /resources/common/gwtswing_resources.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /resources/common/resources/de/exware/gwtswing/icons/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keinhaar/gwtswing/a7ee9a979c4c427544be54f22a9b2b42975483c9/resources/common/resources/de/exware/gwtswing/icons/cancel.png -------------------------------------------------------------------------------- /resources/common/resources/de/exware/gwtswing/icons/file.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 37 | 39 | 40 | 42 | image/svg+xml 43 | 45 | 46 | 47 | 48 | 49 | 51 | 56 | 61 | 66 | 71 | 76 | 81 | 86 | 91 | 92 | -------------------------------------------------------------------------------- /resources/common/resources/de/exware/gwtswing/icons/folder.svg: -------------------------------------------------------------------------------- 1 | 2 | 17 | 19 | 20 | 22 | image/svg+xml 23 | 25 | 26 | 27 | 28 | 29 | 31 | 55 | 60 | 65 | 66 | -------------------------------------------------------------------------------- /resources/common/resources/localization/de.exware.gwtswing.properties: -------------------------------------------------------------------------------- 1 | OK.text=OK 2 | CANCEL.text=Abbrechen 3 | YES.text=Ja 4 | NO.text=Nein 5 | upload.text=Hochladen 6 | upload.file.select.text=Datei auswählen 7 | resetFilter.text=Filter zurücksetzen 8 | OPEN.text=Öffnen 9 | SAVE.text=Speichern -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing.gwt.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/Constants.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing; 2 | 3 | public interface Constants 4 | { 5 | public static final String PLUGIN_ID = "de.exware.gwtswing"; 6 | } 7 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/DefaultStringRenderer.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing; 2 | 3 | 4 | public class DefaultStringRenderer 5 | implements StringRenderer 6 | { 7 | public String toString(T object) 8 | { 9 | if(object != null) 10 | { 11 | return object.toString(); 12 | } 13 | return null; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/StringRenderer.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing; 2 | 3 | /** 4 | * Implementing classes should know how an Object should be represented as String. 5 | * Using this interface will allow us to use different representations in VRadioButtonGroups 6 | * as it is possible with Renderes on Tables and Lists. 7 | * @author martin 8 | */ 9 | public interface StringRenderer 10 | { 11 | public String toString(T object); 12 | } 13 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/AbstractAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import de.exware.gwtswing.PartitionedPanel; 7 | import de.exware.gwtswing.awt.GToolkit; 8 | import de.exware.gwtswing.awt.event.GAWTEvent; 9 | import de.exware.gwtswing.awt.event.GAWTEventListener; 10 | import de.exware.gwtswing.awt.event.GContainerEvent; 11 | import de.exware.gwtswing.swing.GComponent; 12 | import de.exware.gwtswing.swing.GUtilities; 13 | 14 | abstract public class AbstractAnimation implements Animation 15 | { 16 | private static int maxId; 17 | private static Map listeners = new HashMap<>(); 18 | private int id = maxId++; 19 | private TriggerEvent trigger = TriggerEvent.NONE; 20 | private float duration = 1; 21 | 22 | public AbstractAnimation() 23 | { 24 | } 25 | 26 | public AbstractAnimation(TriggerEvent trigger) 27 | { 28 | this.trigger = trigger; 29 | } 30 | 31 | public AbstractAnimation(TriggerEvent trigger, float duration) 32 | { 33 | this(trigger); 34 | this.duration = duration; 35 | } 36 | 37 | @Override 38 | public String getId() 39 | { 40 | return "" + id; 41 | } 42 | 43 | /** 44 | * Installs the Animation to any newly created instance of clazz. 45 | * @param clazz 46 | * @param animation 47 | */ 48 | public static void installGlobally(Class clazz, Animation animation) 49 | { 50 | String key = clazz.getName() + animation.getId(); 51 | GAWTEventListener listener = listeners.get(key); 52 | if(listener == null) 53 | { 54 | listener = new GAWTEventListener() 55 | { 56 | @Override 57 | public void eventDispatched(GAWTEvent event) 58 | { 59 | if(event instanceof GContainerEvent) 60 | { 61 | GComponent comp = (GComponent) event.getSource(); 62 | if(GUtilities.instanceOf(comp, clazz)) 63 | { 64 | animation.install(comp); 65 | } 66 | } 67 | } 68 | }; 69 | listeners.put(key, listener); 70 | GToolkit.getDefaultToolkit().addAWTEventListener(listener, GAWTEvent.CONTAINER_EVENT_MASK); 71 | } 72 | } 73 | 74 | /** 75 | * Stops installing the Animation to any newly created instance of clazz. 76 | * Be aware, that this DOES NOT remove the animation from already created instances. 77 | * @param clazz 78 | * @param animation 79 | */ 80 | public static void stopInstallGlobally(Class clazz, Animation animation) 81 | { 82 | String key = clazz.getName() + animation.getId(); 83 | GAWTEventListener listener = listeners.get(key); 84 | if(listener == null) 85 | { 86 | GToolkit.getDefaultToolkit().removeAWTEventListener(listener); 87 | } 88 | } 89 | 90 | @Override 91 | public TriggerEvent getTriggerEvent() 92 | { 93 | return trigger; 94 | } 95 | 96 | @Override 97 | public void install(GComponent comp) 98 | { 99 | TriggerEvent trigger = getTriggerEvent(); 100 | trigger.install(this, comp); 101 | float duration = getAnimationDuration(); 102 | comp.getPeer().getStyle().setProperty("animationDuration", duration + "s"); 103 | enable(comp); 104 | } 105 | 106 | @Override 107 | public void uninstall(GComponent comp) 108 | { 109 | TriggerEvent trigger = getTriggerEvent(); 110 | trigger.uninstall(this, comp); 111 | disable(comp); 112 | } 113 | 114 | @Override 115 | public float getAnimationDuration() 116 | { 117 | return duration; 118 | } 119 | 120 | public void setAnimationDuration(float seconds) 121 | { 122 | duration = seconds; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/Animation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.swing.GComponent; 4 | 5 | /** 6 | * Interface for Animations of GComponents 7 | * @author martin 8 | * 9 | */ 10 | public interface Animation 11 | { 12 | /** 13 | * Liefert eine eindeutige ID. 14 | * @return 15 | */ 16 | public String getId(); 17 | 18 | /** 19 | * Animation Duration 20 | * @return 21 | */ 22 | public float getAnimationDuration(); 23 | 24 | /** 25 | * Installiert die Animation auf der GComponent. 26 | * @param comp 27 | */ 28 | public void install(GComponent comp); 29 | 30 | /** 31 | * Removes the Animation from the GComponent. 32 | * @param comp 33 | */ 34 | public void uninstall(GComponent comp); 35 | 36 | public TriggerEvent getTriggerEvent(); 37 | 38 | /** 39 | * Used internally to trigger animation. 40 | * Do not call manually! 41 | * @param comp 42 | */ 43 | public void enable(GComponent comp); 44 | 45 | /** 46 | * Used internally to trigger animation 47 | * Do not call manually! 48 | * @param comp 49 | */ 50 | public void disable(GComponent comp); 51 | } 52 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/ExpandHorizontalAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.animation.trigger.VisibilityOnTrigger; 4 | import de.exware.gwtswing.swing.GComponent; 5 | 6 | /** 7 | * Expands the Component from zero width to normal width 8 | * @author martin 9 | */ 10 | public class ExpandHorizontalAnimation extends AbstractAnimation 11 | { 12 | private static final String animationClass = "gwts-animation-expandHorizontal"; 13 | 14 | public ExpandHorizontalAnimation() 15 | { 16 | this(VisibilityOnTrigger.INSTANCE, 0.5f); 17 | } 18 | 19 | public ExpandHorizontalAnimation(TriggerEvent evt, float duration) 20 | { 21 | super(evt, duration); 22 | } 23 | 24 | public ExpandHorizontalAnimation(float duration) 25 | { 26 | this(VisibilityOnTrigger.INSTANCE, duration); 27 | } 28 | 29 | @Override 30 | public 31 | void enable(GComponent comp) 32 | { 33 | comp.getPeer().addClassName(animationClass); 34 | } 35 | 36 | @Override 37 | public 38 | void disable(GComponent comp) 39 | { 40 | comp.getPeer().removeClassName(animationClass); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/ExpandVerticalAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.animation.trigger.VisibilityOnTrigger; 4 | import de.exware.gwtswing.swing.GComponent; 5 | 6 | /** 7 | * Expands the Component from zero height to normal height 8 | * @author martin 9 | */ 10 | public class ExpandVerticalAnimation extends AbstractAnimation 11 | { 12 | private static final String animationClass = "gwts-animation-expandVertical"; 13 | 14 | public ExpandVerticalAnimation() 15 | { 16 | this(VisibilityOnTrigger.INSTANCE, 0.5f); 17 | } 18 | 19 | public ExpandVerticalAnimation(TriggerEvent evt, float duration) 20 | { 21 | super(evt, duration); 22 | } 23 | 24 | @Override 25 | public 26 | void enable(GComponent comp) 27 | { 28 | comp.getPeer().addClassName(animationClass); 29 | } 30 | 31 | @Override 32 | public 33 | void disable(GComponent comp) 34 | { 35 | comp.getPeer().removeClassName(animationClass); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/FadeInAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.animation.trigger.VisibilityOnTrigger; 4 | import de.exware.gwtswing.swing.GComponent; 5 | 6 | /** 7 | * Changes the Opacity of the Component from 0% to 100% 8 | * @author martin 9 | */ 10 | public class FadeInAnimation extends AbstractAnimation 11 | { 12 | private static final String animationClass = "gwts-animation-fadeIn"; 13 | 14 | public FadeInAnimation() 15 | { 16 | this(VisibilityOnTrigger.INSTANCE, 0.5f); 17 | } 18 | 19 | public FadeInAnimation(TriggerEvent evt, float duration) 20 | { 21 | super(evt, duration); 22 | } 23 | 24 | public FadeInAnimation(float duration) 25 | { 26 | this(VisibilityOnTrigger.INSTANCE, duration); 27 | } 28 | 29 | @Override 30 | public 31 | void enable(GComponent comp) 32 | { 33 | comp.getPeer().addClassName(animationClass); 34 | } 35 | 36 | @Override 37 | public 38 | void disable(GComponent comp) 39 | { 40 | comp.getPeer().removeClassName(animationClass); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/FadeInOutAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.animation.trigger.VisibilityTrigger; 4 | import de.exware.gwtswing.swing.GComponent; 5 | 6 | /** 7 | * Changes the Opacity of the Component from 0% to 100% if visibility is set too true, and 8 | * from 100% to 0% if visibility is set to false 9 | * @author martin 10 | */ 11 | public class FadeInOutAnimation extends AbstractAnimation 12 | { 13 | private static final String animationClass = "gwts-animation-fade"; 14 | 15 | public FadeInOutAnimation() 16 | { 17 | this(VisibilityTrigger.INSTANCE, 0.5f); 18 | } 19 | 20 | public FadeInOutAnimation(TriggerEvent evt, float duration) 21 | { 22 | super(evt, duration); 23 | } 24 | 25 | @Override 26 | public 27 | void enable(GComponent comp) 28 | { 29 | comp.getPeer().addClassName(animationClass + (comp.isVisible() ? "In" : "Out")); 30 | } 31 | 32 | @Override 33 | public 34 | void disable(GComponent comp) 35 | { 36 | comp.getPeer().removeClassName(animationClass + (!comp.isVisible() ? "In" : "Out")); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/FadeOutAnimation.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.animation.trigger.VisibilityOffTrigger; 4 | import de.exware.gwtswing.swing.GComponent; 5 | 6 | /** 7 | * Changes the Opacity of the Component from 100% to 0% 8 | * @author martin 9 | */ 10 | public class FadeOutAnimation extends AbstractAnimation 11 | { 12 | private static final String animationClass = "gwts-animation-fadeOut"; 13 | 14 | public FadeOutAnimation() 15 | { 16 | this(VisibilityOffTrigger.INSTANCE, 0.5f); 17 | } 18 | 19 | public FadeOutAnimation(TriggerEvent evt, float duration) 20 | { 21 | super(evt, duration); 22 | } 23 | 24 | public FadeOutAnimation(float duration) 25 | { 26 | this(VisibilityOffTrigger.INSTANCE, duration); 27 | } 28 | 29 | @Override 30 | public 31 | void enable(GComponent comp) 32 | { 33 | if(comp.isVisible() == false) 34 | { 35 | comp.getPeer().addClassName(animationClass); 36 | } 37 | } 38 | 39 | @Override 40 | public 41 | void disable(GComponent comp) 42 | { 43 | comp.getPeer().removeClassName(animationClass); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/TriggerEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation; 2 | 3 | import de.exware.gwtswing.swing.GComponent; 4 | 5 | /** 6 | * Event that Triggers the Animation 7 | * @author martin 8 | */ 9 | abstract public class TriggerEvent 10 | { 11 | public static final TriggerEvent NONE = new TriggerEvent() 12 | { 13 | @Override 14 | protected void install(Animation animation, GComponent comp) 15 | { 16 | } 17 | @Override 18 | protected void uninstall(Animation animation, GComponent comp) 19 | { 20 | } 21 | }; 22 | 23 | protected abstract void install(Animation animation, GComponent comp); 24 | 25 | protected abstract void uninstall(Animation animation, GComponent comp); 26 | } -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/trigger/VisibilityOffTrigger.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation.trigger; 2 | 3 | import de.exware.gwtswing.animation.Animation; 4 | import de.exware.gwtswing.animation.TriggerEvent; 5 | import de.exware.gwtswing.awt.event.GComponentAdapter; 6 | import de.exware.gwtswing.awt.event.GComponentEvent; 7 | import de.exware.gwtswing.swing.GComponent; 8 | 9 | /** 10 | * Triggers the Animation if visibility is set too false 11 | * @author martin 12 | */ 13 | public class VisibilityOffTrigger extends TriggerEvent 14 | { 15 | public static final VisibilityOffTrigger INSTANCE = new VisibilityOffTrigger(); 16 | 17 | private VisibilityOffTrigger() 18 | { 19 | } 20 | 21 | @Override 22 | protected void install(Animation animation, GComponent comp) 23 | { 24 | GComponentAdapter adapter = new GComponentAdapter() 25 | { 26 | @Override 27 | public void componentShown(GComponentEvent e) 28 | { 29 | animation.disable(comp); 30 | } 31 | 32 | @Override 33 | public void componentHidden(GComponentEvent e) 34 | { 35 | animation.enable(comp); 36 | } 37 | }; 38 | comp.addComponentListener(adapter); 39 | comp.putClientProperty("AnimationAdapter-" + getClass().getName(), adapter); 40 | } 41 | 42 | @Override 43 | protected void uninstall(Animation animation, GComponent comp) 44 | { 45 | GComponentAdapter adapter = (GComponentAdapter) comp.getClientProperty("AnimationAdapter-" + getClass().getName()); 46 | comp.removeComponentListener(adapter); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/trigger/VisibilityOnTrigger.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation.trigger; 2 | 3 | import de.exware.gwtswing.animation.Animation; 4 | import de.exware.gwtswing.animation.TriggerEvent; 5 | import de.exware.gwtswing.awt.event.GComponentAdapter; 6 | import de.exware.gwtswing.awt.event.GComponentEvent; 7 | import de.exware.gwtswing.swing.GComponent; 8 | 9 | /** 10 | * Triggers the Animation if visibility is set too true 11 | * @author martin 12 | */ 13 | public class VisibilityOnTrigger extends TriggerEvent 14 | { 15 | public static final VisibilityOnTrigger INSTANCE = new VisibilityOnTrigger(); 16 | 17 | private VisibilityOnTrigger() 18 | { 19 | } 20 | 21 | @Override 22 | protected void install(Animation animation, GComponent comp) 23 | { 24 | GComponentAdapter adapter = new GComponentAdapter() 25 | { 26 | @Override 27 | public void componentShown(GComponentEvent e) 28 | { 29 | animation.enable(comp); 30 | } 31 | 32 | @Override 33 | public void componentHidden(GComponentEvent e) 34 | { 35 | animation.disable(comp); 36 | } 37 | }; 38 | comp.addComponentListener(adapter); 39 | comp.putClientProperty("AnimationAdapter-" + getClass().getName(), adapter); 40 | } 41 | 42 | @Override 43 | protected void uninstall(Animation animation, GComponent comp) 44 | { 45 | GComponentAdapter adapter = (GComponentAdapter) comp.getClientProperty("AnimationAdapter-" + getClass().getName()); 46 | comp.removeComponentListener(adapter); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/animation/trigger/VisibilityTrigger.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.animation.trigger; 2 | 3 | import de.exware.gwtswing.animation.Animation; 4 | import de.exware.gwtswing.animation.TriggerEvent; 5 | import de.exware.gwtswing.awt.event.GComponentAdapter; 6 | import de.exware.gwtswing.awt.event.GComponentEvent; 7 | import de.exware.gwtswing.swing.GComponent; 8 | 9 | /** 10 | * Triggers the Animation if visibility is changed 11 | * @author martin 12 | */ 13 | public class VisibilityTrigger extends TriggerEvent 14 | { 15 | public static final VisibilityTrigger INSTANCE = new VisibilityTrigger(); 16 | 17 | private VisibilityTrigger() 18 | { 19 | } 20 | 21 | @Override 22 | protected void install(Animation animation, GComponent comp) 23 | { 24 | GComponentAdapter adapter = new GComponentAdapter() 25 | { 26 | @Override 27 | public void componentShown(GComponentEvent e) 28 | { 29 | animation.disable(comp); 30 | animation.enable(comp); 31 | } 32 | 33 | @Override 34 | public void componentHidden(GComponentEvent e) 35 | { 36 | animation.disable(comp); 37 | animation.enable(comp); 38 | } 39 | }; 40 | comp.addComponentListener(adapter); 41 | comp.putClientProperty("AnimationAdapter-" + getClass().getName(), adapter); 42 | } 43 | 44 | @Override 45 | protected void uninstall(Animation animation, GComponent comp) 46 | { 47 | GComponentAdapter adapter = (GComponentAdapter) comp.getClientProperty("AnimationAdapter-" + getClass().getName()); 48 | comp.removeComponentListener(adapter); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GCanvas.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | import de.exware.gplatform.GPlatform; 4 | import de.exware.gplatform.element.GPCanvasElement; 5 | import de.exware.gwtswing.swing.GComponent; 6 | 7 | public class GCanvas extends GComponent 8 | { 9 | public GCanvas() 10 | { 11 | super(GPlatform.getDoc().createCanvasElement()); 12 | } 13 | 14 | public GGraphics2D getGraphics() 15 | { 16 | GPCanvasElement ce = (GPCanvasElement) getPeer(); 17 | return new GGraphics2D(ce.getContext2d()); 18 | } 19 | 20 | @Override 21 | public void setBounds(int x, int y, int width, int height) 22 | { 23 | super.setBounds(x, y, width, height); 24 | GPCanvasElement ce = (GPCanvasElement) getPeer(); 25 | ce.setWidth(width); 26 | ce.setHeight(height); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GCardLayout.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.swing.GComponent; 7 | 8 | public class GCardLayout implements GLayoutManager 9 | { 10 | private int current = -1; 11 | private List names = new ArrayList<>(); 12 | 13 | /** 14 | * Adds the specified component with the specified name to the layout. 15 | * 16 | * @param name 17 | * the component name 18 | * @param comp 19 | * the component to be added 20 | */ 21 | @Override 22 | public void addLayoutComponent(String name, GComponent comp) 23 | { 24 | names.add(name); 25 | } 26 | 27 | /** 28 | * Removes the specified component from the layout. 29 | * 30 | * @param comp 31 | * the component to be removed 32 | */ 33 | @Override 34 | public void removeLayoutComponent(GComponent comp) 35 | { 36 | } 37 | 38 | public void show(GComponent comp, String name) 39 | { 40 | for(int i=0;i pref.width ? dim.width : pref.width; 69 | dim.height = dim.height > pref.height ? dim.height : pref.height; 70 | } 71 | dim.width += insets.left + insets.right; 72 | dim.height += insets.top + insets.bottom; 73 | return dim; 74 | } 75 | 76 | /** 77 | * Calculates the minimum size dimensions for the specified panel given the 78 | * components in the specified parent container. 79 | * 80 | * @param parent 81 | * the component to be laid out 82 | * @see #preferredLayoutSize 83 | */ 84 | @Override 85 | public GDimension minimumLayoutSize(GComponent parent) 86 | { 87 | int count = parent.getComponentCount(); 88 | GDimension dim = new GDimension(); 89 | for (int i = 0; i < count; i++) 90 | { 91 | GDimension pref = parent.getComponent(i).getMinimumSize(); 92 | dim.width = dim.width > pref.width ? dim.width : pref.width; 93 | dim.height = dim.height > pref.height ? dim.height : pref.height; 94 | } 95 | return dim; 96 | } 97 | 98 | /** 99 | * Lays out the container in the specified panel. 100 | * 101 | * @param parent 102 | * the component which needs to be laid out 103 | */ 104 | @Override 105 | public void layoutContainer(GComponent parent) 106 | { 107 | int count = parent.getComponentCount(); 108 | for (int i = 0; i < count; i++) 109 | { 110 | GComponent comp = parent.getComponent(i); 111 | GInsets insets = parent.getInsets(); 112 | GDimension dim = parent.getSize(); 113 | if(i == current) 114 | { 115 | comp.setBounds(0, 0, dim.width - insets.left - insets.right, 116 | dim.height - insets.top - insets.bottom); 117 | comp.setVisible(true); 118 | } 119 | else 120 | { 121 | comp.setBounds(insets.left, insets.top, 0,0); 122 | comp.setVisible(false); 123 | } 124 | } 125 | } 126 | 127 | @Override 128 | public void addLayoutComponent(GComponent comp, Object constraints) 129 | { 130 | addLayoutComponent((String)constraints, comp); 131 | if(names.size() == 1) 132 | { 133 | current = 0; 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GCursor.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | public enum GCursor 4 | { 5 | DEFAULT_CURSOR("default") 6 | , CROSSHAIR_CURSOR("crosshair") 7 | , COLUMN_RESIZE_CURSOR("col-resize") 8 | , HORIZONTAL_RESIZE_CURSOR("ew-resize") 9 | , VERTICAL_RESIZE_CURSOR("ns-resize") 10 | ; 11 | 12 | private String cursorName; 13 | 14 | private GCursor(String cursorName) 15 | { 16 | this.cursorName = cursorName; 17 | } 18 | 19 | public String getCursorName() 20 | { 21 | return cursorName; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GDimension.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | public class GDimension 4 | { 5 | public int width, height; 6 | 7 | public GDimension(int w, int h) 8 | { 9 | this.width = w; 10 | this.height = h; 11 | } 12 | 13 | public GDimension() 14 | { 15 | } 16 | 17 | public GDimension(GDimension dim) 18 | { 19 | this.width = dim.width; 20 | this.height = dim.height; 21 | } 22 | 23 | public int getWidth() 24 | { 25 | return width; 26 | } 27 | 28 | public int getHeight() 29 | { 30 | return height; 31 | } 32 | 33 | @Override 34 | public String toString() 35 | { 36 | return "GDimension " + width + " / " + height; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object obj) 41 | { 42 | if(obj == this) return true; 43 | if(obj instanceof GDimension) 44 | { 45 | GDimension dim = (GDimension) obj; 46 | return width == dim.width && height == dim.height; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GFont.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | 4 | public class GFont 5 | { 6 | public static final int PLAIN = 0; 7 | public static final int BOLD = 1; 8 | public static final int ITALIC = 2; 9 | 10 | private String familyName; 11 | private int size; 12 | private int style = PLAIN; 13 | 14 | public GFont(String familyName, int style, int size) 15 | { 16 | this.familyName = familyName; 17 | this.size = size; 18 | this.style = style; 19 | } 20 | 21 | public float getSize2D() 22 | { 23 | return size; 24 | } 25 | 26 | public GFont deriveFont(float size) 27 | { 28 | return new GFont(familyName, style, (int) size); 29 | } 30 | 31 | public GFont deriveFont(int style) 32 | { 33 | return new GFont(familyName, style, size); 34 | } 35 | 36 | public String getFamily() 37 | { 38 | return familyName; 39 | } 40 | 41 | public int getStyle() 42 | { 43 | return style; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | return familyName + ";" + size + ";" + style; 50 | } 51 | 52 | /** 53 | * Gibt den Font CSS kompatibel aus. 54 | * @return 55 | */ 56 | public String toCSS() 57 | { 58 | return (getStyle() == GFont.BOLD ? "bold" : "normal") 59 | + " " + getSize2D() + "px " 60 | + " " + getFamily(); 61 | } 62 | 63 | @Override 64 | public boolean equals(Object obj) 65 | { 66 | boolean eq = obj == this; 67 | if(eq == false && obj instanceof GFont) 68 | { 69 | eq = toCSS().equals(((GFont)obj).toCSS()); 70 | } 71 | return eq; 72 | } 73 | 74 | @Override 75 | public int hashCode() 76 | { 77 | return size + style + familyName.hashCode(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GFontMetrics.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gplatform.GPlatform; 5 | import de.exware.gwtswing.swing.GLabel; 6 | import de.exware.gwtswing.swing.GUtilities; 7 | 8 | public class GFontMetrics 9 | { 10 | private GFont font; 11 | private int height = -1; 12 | 13 | public GFontMetrics(GFont font) 14 | { 15 | this.font = font; 16 | } 17 | 18 | public int stringWidth(String text) 19 | { 20 | return (int) GPlatform.getInstance().stringWidth(font.toCSS(), text); 21 | } 22 | 23 | public int getHeight() 24 | { 25 | if(height == -1) 26 | { 27 | GPElement el = GUtilities.getMeasureElement(); 28 | GLabel label = new GLabel("agZÜW"); 29 | label.setFont(font); 30 | GPElement peer = label.getPeer(); 31 | peer.getStyle().setPosition("relative"); 32 | peer.getStyle().setDisplay("inline"); 33 | peer.getStyle().setVisibility("visible"); 34 | el.appendChild(peer); 35 | height = peer.getOffsetHeight(); 36 | el.removeChild(peer); 37 | } 38 | return height; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GGraphics2D.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import de.exware.gplatform.element.GPContext2d; 7 | import de.exware.gwtswing.awt.geom.Ellipse2D; 8 | 9 | /** 10 | * A Swing like GGraphics2D Context. 11 | * @author martin 12 | * 13 | */ 14 | public class GGraphics2D 15 | { 16 | private GPContext2d graphics; 17 | private GFont font; 18 | private static Map metricsCache = new HashMap<>(); 19 | 20 | public GGraphics2D(GPContext2d graphics) 21 | { 22 | this.graphics = graphics; 23 | graphics.setTransform(1,0,0,1,0,0); 24 | } 25 | 26 | public void drawLine(int x1, int y1, int x2, int y2) 27 | { 28 | graphics.save(); 29 | graphics.translate(0.5, 0.5); 30 | graphics.moveTo(x1, y1); 31 | graphics.lineTo( x2, y2); 32 | graphics.stroke(); 33 | graphics.restore(); 34 | } 35 | 36 | public void drawRect(int x, int y, int width, int height) 37 | { 38 | graphics.save(); 39 | graphics.translate(0.5, 0.5); 40 | graphics.rect(x, y, width, height); 41 | graphics.stroke(); 42 | graphics.restore(); 43 | } 44 | 45 | public void draw(GShape shape) 46 | { 47 | if(shape instanceof Ellipse2D) 48 | { 49 | Ellipse2D ell = (Ellipse2D) shape; 50 | drawEllipseHelper(graphics, false, ell.getX(), ell.getY(), ell.getWidth(), ell.getHeight()); 51 | } 52 | else 53 | { 54 | throw new UnsupportedOperationException("This type of Shape is not supported: " + shape.getClass().getName()); 55 | } 56 | } 57 | 58 | public void fill(GShape shape) 59 | { 60 | if(shape instanceof Ellipse2D) 61 | { 62 | Ellipse2D ell = (Ellipse2D) shape; 63 | drawEllipseHelper(graphics, true, ell.getX(), ell.getY(), ell.getWidth(), ell.getHeight()); 64 | } 65 | else 66 | { 67 | throw new UnsupportedOperationException("This type of Shape is not supported: " + shape.getClass().getName()); 68 | } 69 | } 70 | 71 | private static void drawEllipseHelper(GPContext2d ctx, boolean fill, double x, double y, double w, double h) 72 | { 73 | double kappa = .5522848f; 74 | double ox = w / 2 * kappa; // control point offset horizontal 75 | double oy = h / 2 * kappa; // control point offset vertical 76 | double xe = x + w; // x-end 77 | double ye = y + h; // y-end 78 | double xm = x + w / 2; // x-middle 79 | double ym = y + h / 2; // y-middle 80 | 81 | ctx.beginPath(); 82 | ctx.moveTo(x, ym); 83 | ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); 84 | ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); 85 | ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); 86 | ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); 87 | ctx.stroke(); 88 | if (fill) 89 | { 90 | ctx.fill(); 91 | } 92 | } 93 | 94 | public void fillRect(int x, int y, int width, int height) 95 | { 96 | graphics.fillRect(x, y, width, height); 97 | } 98 | 99 | public void drawString(String text, int x, int y) 100 | { 101 | graphics.fillText(text, x, y); 102 | } 103 | 104 | public void setColor(GColor color) 105 | { 106 | graphics.setStrokeColor(color.toHex()); 107 | graphics.setFillColor(color.toHex()); 108 | } 109 | 110 | public void drawImage(GImage image, int x, int y) 111 | { 112 | graphics.drawImage(image.getImageElement(), x, y); 113 | } 114 | 115 | public void drawImage(GImage image, int x, int y, int w, int h) 116 | { 117 | graphics.drawImage(image.getImageElement(), x, y, w, h); 118 | } 119 | 120 | public void drawImage(GImage image, int destX, int destY, int destX2, int destY2, int srcX, int srcY, int srcX2, int srcY2) 121 | { 122 | graphics.drawImage(image.getImageElement() 123 | , srcX, srcY, srcX2-srcX, srcY2-srcY 124 | , destX, destY, destX2-destX, destY2-destY); 125 | } 126 | 127 | public void setTransform() 128 | { 129 | graphics.rotate(90); 130 | } 131 | 132 | /** 133 | * Rotation in Radians. 134 | * @param rotate 135 | */ 136 | public void setRotate(double rotate) 137 | { 138 | graphics.rotate(rotate); 139 | } 140 | 141 | /** 142 | * Rotation in Radians. 143 | * @param rotate 144 | */ 145 | public void setTranslate(double x, double y) 146 | { 147 | graphics.translate(x, y); 148 | } 149 | 150 | /** 151 | * Scaling. 152 | * @param 153 | */ 154 | public void setScale(double x, double y) 155 | { 156 | graphics.scale(x, y); 157 | } 158 | 159 | public void setFont(GFont gFont) 160 | { 161 | graphics.setFont(gFont.toCSS()); 162 | this.font = gFont; 163 | } 164 | 165 | public GFontMetrics getFontMetrics() 166 | { 167 | GFontMetrics fm = metricsCache.get(font); 168 | if(fm == null) 169 | { 170 | fm = new GFontMetrics(font); 171 | metricsCache.put(font, fm); 172 | } 173 | return fm; 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GGridBagConstraints.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | public class GGridBagConstraints 4 | { 5 | /** 6 | * Do not resize the component. 7 | */ 8 | public static final int NONE = 0; 9 | 10 | /** 11 | * Resize the component both horizontally and vertically. 12 | */ 13 | public static final int BOTH = 1; 14 | 15 | /** 16 | * Resize the component horizontally but not vertically. 17 | */ 18 | public static final int HORIZONTAL = 2; 19 | 20 | /** 21 | * Resize the component vertically but not horizontally. 22 | */ 23 | public static final int VERTICAL = 3; 24 | 25 | public static final int CENTER = 10; 26 | public static final int NORTH = 11; 27 | public static final int NORTHEAST = 12; 28 | public static final int EAST = 13; 29 | public static final int SOUTHEAST = 14; 30 | public static final int SOUTH = 15; 31 | public static final int SOUTHWEST = 16; 32 | public static final int WEST = 17; 33 | public static final int NORTHWEST = 18; 34 | 35 | public static final int RELATIVE = -1; 36 | public static final int REMAINDER = 0; 37 | 38 | public static final int PAGE_START = 19; 39 | 40 | public static final int PAGE_END = 20; 41 | 42 | public static final int LINE_START = 21; 43 | 44 | public static final int LINE_END = 22; 45 | 46 | public static final int FIRST_LINE_START = 23; 47 | 48 | public static final int FIRST_LINE_END = 24; 49 | 50 | public static final int LAST_LINE_START = 25; 51 | 52 | public static final int LAST_LINE_END = 26; 53 | 54 | public int gridx = 0; 55 | public int gridy = 0; 56 | public int gridwidth = 1; 57 | public int gridheight = 1; 58 | public GInsets insets = new GInsets(); 59 | public int fill = -1; 60 | public int anchor = -1; 61 | public int ipadx; 62 | public double weighty; 63 | public int ipady; 64 | public double weightx; 65 | 66 | public GGridBagConstraints clone() 67 | { 68 | GGridBagConstraints clone = new GGridBagConstraints(); 69 | clone.gridx = gridx; 70 | clone.gridy = gridy; 71 | clone.gridwidth = gridwidth; 72 | clone.gridheight = gridheight; 73 | clone.insets.left = insets.left; 74 | clone.insets.top = insets.top; 75 | clone.insets.right = insets.right; 76 | clone.insets.bottom = insets.bottom; 77 | clone.weightx = weightx; 78 | clone.weighty = weighty; 79 | clone.fill = fill; 80 | clone.anchor = anchor; 81 | return clone; 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GGridBagLayoutInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | /** 18 | * @author Michael Danilov 19 | */ 20 | package de.exware.gwtswing.awt; 21 | 22 | class GGridBagLayoutInfo { 23 | 24 | int widths[]; 25 | int heights[]; 26 | 27 | GGridBagLayoutInfo(int widths[], int heights[]) { 28 | this.widths = widths; 29 | this.heights = heights; 30 | } 31 | 32 | void update(int widths[], int heights[]) { 33 | this.widths = widths; 34 | this.heights = heights; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/GGridLayout.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt; 2 | 3 | import de.exware.gwtswing.swing.GComponent; 4 | 5 | public class GGridLayout implements GLayoutManager 6 | { 7 | private int rowCount; 8 | private int columnCount; 9 | private int horGap; 10 | private int vertGap; 11 | 12 | public GGridLayout(int rows,int cols) 13 | { 14 | this(rows,cols,0,0); 15 | } 16 | 17 | public GGridLayout(int rows,int cols,int hgap,int vgap) 18 | { 19 | rowCount = rows; 20 | columnCount = cols; 21 | horGap = hgap; 22 | vertGap = vgap; 23 | } 24 | 25 | /** 26 | * Calculates the preferred size dimensions for the specified 27 | * panel given the components in the specified parent container. 28 | * @param parent the component to be laid out 29 | * 30 | * @see #minimumLayoutSize 31 | */ 32 | @Override 33 | public GDimension preferredLayoutSize(GComponent parent) 34 | { 35 | int count = parent.getComponentCount(); 36 | GInsets insets = parent.getInsets(); 37 | GDimension dim = new GDimension(); 38 | for(int i=0;i pref.width ? dim.width : pref.width; 42 | dim.height = dim.height > pref.height ? dim.height : pref.height; 43 | } 44 | dim.width = (dim.width * columnCount) + ((columnCount-1) * horGap);// + insets.left + insets.right; 45 | int rows = rowCount; 46 | if(rowCount == 0) 47 | { 48 | rows = Math.round(1.0F * parent.getComponentCount() / columnCount); 49 | } 50 | dim.height = (dim.height * rows) + ((rows-1) * vertGap); // + insets.top + insets.bottom; 51 | return dim; 52 | } 53 | 54 | /** 55 | * Calculates the minimum size dimensions for the specified 56 | * panel given the components in the specified parent container. 57 | * @param parent the component to be laid out 58 | * @see #preferredLayoutSize 59 | */ 60 | @Override 61 | public GDimension minimumLayoutSize(GComponent parent) 62 | { 63 | int count = parent.getComponentCount(); 64 | GDimension dim = new GDimension(); 65 | for(int i=0;i pref.width ? dim.width : pref.width; 69 | dim.height = dim.height > pref.height ? dim.height : pref.height; 70 | } 71 | return dim; 72 | } 73 | 74 | /** 75 | * Lays out the container in the specified panel. 76 | * @param parent the component which needs to be laid out 77 | */ 78 | @Override 79 | public void layoutContainer(GComponent parent) 80 | { 81 | if(parent.getComponentCount() == 0) 82 | { 83 | return; 84 | } 85 | GDimension size = parent.getSize(); 86 | if(size.width<1 && size.height<1) 87 | { 88 | return; 89 | } 90 | GInsets insets = parent.getInsets(); 91 | int colWidth = size.width - insets.left - insets.right - ((columnCount-1)*horGap); 92 | colWidth = colWidth / columnCount; 93 | int rows = rowCount; 94 | if(rowCount == 0) 95 | { 96 | rows = Math.round(1.0F * parent.getComponentCount() / columnCount); 97 | } 98 | int rowHeight = size.height - insets.top - insets.bottom - ((rows-1)*vertGap); 99 | rowHeight = rowHeight / rows; 100 | int ypos = 0; 101 | int i =0; 102 | for(;i touches = jsEvent.getTouches(); 28 | points = new GPoint[touches.size()]; 29 | for(int i=0;i x 57 | && rect.getY() + rect.getHeight() > y 58 | && rect.getX() < x + getWidth() 59 | && rect.getY() < y + getHeight(); 60 | } 61 | 62 | @Override 63 | public String toString() 64 | { 65 | return getClass().getSimpleName() + " (" + getX() + ","+ getY() + "," + getWidth() + "," + getHeight() + ")"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/geom/Rectangle2D.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt.geom; 2 | 3 | 4 | public abstract class Rectangle2D extends RectangularShape 5 | { 6 | public static class Double extends Rectangle2D 7 | { 8 | public double x; 9 | public double y; 10 | public double width; 11 | public double height; 12 | 13 | public Double() 14 | { 15 | 16 | } 17 | 18 | public Double(double x,double y,double w,double h) 19 | { 20 | this.x = x; 21 | this.y = y; 22 | width = w; 23 | height = h; 24 | } 25 | 26 | @Override 27 | public double getX() 28 | { 29 | return x; 30 | } 31 | 32 | @Override 33 | public double getY() 34 | { 35 | return y; 36 | } 37 | 38 | @Override 39 | public double getWidth() 40 | { 41 | return width; 42 | } 43 | 44 | @Override 45 | public double getHeight() 46 | { 47 | return height; 48 | } 49 | } 50 | 51 | @Override 52 | public boolean intersects(Rectangle2D rect) 53 | { 54 | double x = getX(); 55 | double y = getY(); 56 | return rect.getX() + rect.getWidth() > x 57 | && rect.getY() + rect.getHeight() > y 58 | && rect.getX() < x + getWidth() 59 | && rect.getY() < y + getHeight(); 60 | } 61 | 62 | @Override 63 | public String toString() 64 | { 65 | return getClass().getSimpleName() + " (" + getX() + ","+ getY() + "," + getWidth() + "," + getHeight() + ")"; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/awt/geom/RectangularShape.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.awt.geom; 2 | 3 | import de.exware.gwtswing.awt.GPoint; 4 | import de.exware.gwtswing.awt.GShape; 5 | 6 | abstract public class RectangularShape implements GShape 7 | { 8 | 9 | @Override 10 | public boolean contains(GPoint p) 11 | { 12 | return contains(p.x, p.y); 13 | } 14 | 15 | @Override 16 | public boolean contains(int x, int y) 17 | { 18 | return x > getX() && x < getX()+getWidth() 19 | && y > getY() && y < getY()+getHeight(); 20 | } 21 | 22 | abstract public double getX(); 23 | abstract public double getY(); 24 | abstract public double getWidth(); 25 | abstract public double getHeight(); 26 | } 27 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GAbstractAction.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import de.exware.gwtswing.awt.event.GActionEvent; 9 | import de.exware.gwtswing.swing.event.GPropertyChangeEvent; 10 | import de.exware.gwtswing.swing.event.GPropertyChangeListener; 11 | 12 | /** 13 | * Actions can be used in Menus and/or Toolbars. 14 | */ 15 | abstract public class GAbstractAction implements GAction 16 | { 17 | private Map values = new HashMap<>(); 18 | private boolean enabled = true; 19 | private List listeners; 20 | 21 | public GAbstractAction(String name) 22 | { 23 | values.put(NAME, name); 24 | } 25 | 26 | @Override 27 | public void actionPerformed(GActionEvent evt) 28 | { 29 | } 30 | 31 | @Override 32 | public void putValue(String key, Object value) 33 | { 34 | values.put(key, value); 35 | firePropertyChanged(key, value); 36 | } 37 | 38 | @Override 39 | public Object getValue(String key) 40 | { 41 | return values.get(key); 42 | } 43 | 44 | @Override 45 | public void addPropertyChangeListener(GPropertyChangeListener li) 46 | { 47 | if (listeners == null) listeners = new ArrayList<>(); 48 | if(listeners.contains(li) == false) 49 | { 50 | listeners.add(li); 51 | } 52 | } 53 | 54 | @Override 55 | public void removePropertyChangeListener(GPropertyChangeListener li) 56 | { 57 | if (listeners != null) 58 | { 59 | listeners.remove(li); 60 | } 61 | } 62 | 63 | @Override 64 | public void setEnabled(boolean b) 65 | { 66 | enabled = b; 67 | firePropertyChanged(ENABLED_PROPERTY, b); 68 | } 69 | 70 | @Override 71 | public boolean isEnabled() 72 | { 73 | return enabled; 74 | } 75 | 76 | private void firePropertyChanged(String property, Object value) 77 | { 78 | GPropertyChangeEvent evt = new GPropertyChangeEvent(this, property, value); 79 | for (int i = 0; listeners != null && i < listeners.size(); i++) 80 | { 81 | GPropertyChangeListener li = listeners.get(i); 82 | li.propertyChanged(evt); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GAbstractListModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.swing.event.GListDataEvent; 7 | import de.exware.gwtswing.swing.event.GListDataListener; 8 | 9 | abstract public class GAbstractListModel 10 | implements GListModel 11 | { 12 | private List listeners = new ArrayList<>(); 13 | 14 | @Override 15 | public void addListDataListener(GListDataListener l) 16 | { 17 | listeners.add(l); 18 | } 19 | 20 | @Override 21 | public void removeListDataListener(GListDataListener l) 22 | { 23 | listeners.remove(l); 24 | } 25 | 26 | protected void fireIntervalAdded(int minIndex, int maxIndex) 27 | { 28 | GListDataEvent evt = new GListDataEvent(this, GListDataEvent.INTERVAL_ADDED, minIndex, maxIndex); 29 | for(int i=0;i icon.getIconHeight() ? dim.height : icon.getIconHeight() + extraheight; 162 | } 163 | } 164 | return dim; 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GButtonGroup.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.awt.event.GActionEvent; 7 | import de.exware.gwtswing.awt.event.GActionListener; 8 | 9 | public class GButtonGroup 10 | { 11 | private static int groupCounter; 12 | private String group; 13 | private List buttons = new ArrayList<>(); 14 | private ButtonGroupListener listener = new ButtonGroupListener(); 15 | 16 | public GButtonGroup() 17 | { 18 | group = "" + groupCounter++; 19 | } 20 | 21 | public void add(GAbstractButton bt) 22 | { 23 | buttons.add(bt); 24 | if(bt instanceof GRadioButton) 25 | { 26 | ((GRadioButton)bt).setButtonGroup(group); 27 | } 28 | else if(bt instanceof GToggleButton) 29 | { 30 | bt.addActionListener(listener); 31 | } 32 | } 33 | 34 | class ButtonGroupListener implements GActionListener 35 | { 36 | @Override 37 | public void actionPerformed(GActionEvent evt) 38 | { 39 | GAbstractButton source = (GAbstractButton) evt.getSource(); 40 | for(int i=0;i gl.getSize().getHeight() ? label.getOffsetHeight() 86 | : gl.getSize().getHeight(); 87 | div.removeChild(clone); 88 | setCachedPreferredSize(dim); 89 | } 90 | return dim; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GComboBoxModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GComboBoxModel extends GListModel 4 | { 5 | void setSelectedItem(E anItem); 6 | 7 | E getSelectedItem(); 8 | } 9 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GDefaultComboBoxModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class GDefaultComboBoxModel extends GAbstractListModel 7 | implements GMutableComboBoxModel 8 | { 9 | private E selectedItem; 10 | private List items = new ArrayList<>(); 11 | 12 | public GDefaultComboBoxModel() 13 | { 14 | } 15 | 16 | public GDefaultComboBoxModel(E[] el) 17 | { 18 | for(int i=0;i implements GListCellRenderer 4 | { 5 | @Override 6 | public GComponent getListCellRendererComponent(GList list, T value, boolean selected) 7 | { 8 | GLabel label = new GLabel(value == null ? "" : value.toString()); 9 | label.setOpaque(selected); 10 | if(selected) 11 | { 12 | label.setBackground(GUIManager.getColor(".gwts-GList-selected/background-color")); 13 | } 14 | return label; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GDefaultListModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class GDefaultListModel extends GAbstractListModel 7 | implements GListModel 8 | { 9 | private List list = new ArrayList<>(); 10 | 11 | public GDefaultListModel() 12 | { 13 | } 14 | 15 | public GDefaultListModel(List data) 16 | { 17 | list.addAll(data); 18 | } 19 | 20 | public GDefaultListModel(T[] data) 21 | { 22 | for(int i=0;i getData() 71 | { 72 | return new ArrayList<>(list); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GDialog.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.awt.GToolkit; 4 | import de.exware.gwtswing.awt.GWindow; 5 | import de.exware.gwtswing.awt.event.GAWTEvent; 6 | import de.exware.gwtswing.awt.event.GAWTEventListener; 7 | import de.exware.gwtswing.awt.event.GKeyEvent; 8 | 9 | public class GDialog extends GWindow 10 | { 11 | private GDialogCallback callback; 12 | private GAbstractButton defaultButton; 13 | private GAWTEventListener listener; 14 | private boolean isModal = false; 15 | 16 | public GDialog() 17 | { 18 | this((GFrame)null, (GDialogCallback)null); 19 | } 20 | 21 | public GDialog(GDialogCallback callback) 22 | { 23 | this((GWindow)null, callback); 24 | } 25 | 26 | public GDialog(GWindow parent, GDialogCallback callback) 27 | { 28 | this(parent, null, callback); 29 | } 30 | 31 | public GDialog(GWindow parent, String title, GDialogCallback callback) 32 | { 33 | this(parent, title, false, callback); 34 | } 35 | 36 | public GDialog(GWindow parent, String title) 37 | { 38 | this(parent, title, false, null); 39 | } 40 | 41 | public GDialog(GWindow parent, String title, boolean modal) 42 | { 43 | this(parent, title, modal, null); 44 | } 45 | 46 | public GDialog(GWindow parent, String title, boolean modal, GDialogCallback callback) 47 | { 48 | this.callback = callback; 49 | setTitle(title); 50 | setModal(modal); 51 | } 52 | 53 | public void setModal(boolean modal) 54 | { 55 | if(modal != isModal) 56 | { 57 | isModal = modal; 58 | } 59 | } 60 | 61 | protected void callback() 62 | { 63 | callback.execute(this); 64 | } 65 | 66 | public void dispose() 67 | { 68 | setVisible(false); 69 | } 70 | 71 | public void hide() 72 | { 73 | setVisible(false); 74 | } 75 | 76 | @Override 77 | public void setVisible(boolean visible) 78 | { 79 | super.setVisible(visible); 80 | if(visible == false && callback != null) 81 | { 82 | callback(); 83 | } 84 | if(visible) 85 | { 86 | if(isModal) 87 | { 88 | setModalComponent(this); 89 | } 90 | listener = new GAWTEventListener() 91 | { 92 | @Override 93 | public void eventDispatched(GAWTEvent event) 94 | { 95 | if(defaultButton != null) 96 | { 97 | GKeyEvent evt = (GKeyEvent) event; 98 | if(evt.getId() == GKeyEvent.KEY_RELEASED) 99 | { 100 | int kc1 = evt.getKeyCode(); 101 | int kc2 = GKeyEvent.VK_ENTER; 102 | if(kc1 == kc2) 103 | { 104 | defaultButton.doClick(); 105 | } 106 | } 107 | } 108 | } 109 | }; 110 | GToolkit.getDefaultToolkit().addAWTEventListener(listener, GAWTEvent.KEY_EVENT_MASK); 111 | GUtilities.focusFirstField(this); 112 | } 113 | else 114 | { 115 | GToolkit.getDefaultToolkit().removeAWTEventListener(listener); 116 | if(isModal) 117 | { 118 | removeModalComponent(); 119 | } 120 | } 121 | } 122 | 123 | public GAbstractButton getDefaultButton() 124 | { 125 | return defaultButton; 126 | } 127 | 128 | public void setDefaultButton(GAbstractButton defaultButton) 129 | { 130 | defaultButton.getPeer().addClassName("gwts-GDialog-defaultButton"); 131 | this.defaultButton = defaultButton; 132 | } 133 | 134 | public void setCallback(GDialogCallback callback) 135 | { 136 | this.callback = callback; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GDialogCallback.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GDialogCallback 4 | { 5 | public void execute(T dlg); 6 | } -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GFrame.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.Objects; 4 | 5 | import de.exware.gwtswing.awt.GBorderLayout; 6 | import de.exware.gwtswing.awt.GGridBagConstraints; 7 | import de.exware.gwtswing.awt.GGridBagLayout; 8 | import de.exware.gwtswing.awt.GWindow; 9 | 10 | public class GFrame extends GWindow 11 | { 12 | private GPanel toolbarMenuContainer; 13 | private GMenuBar menubar; 14 | private GToolBar toolbar; 15 | 16 | public GFrame() 17 | { 18 | } 19 | 20 | public void setGToolBar(GToolBar tbar) 21 | { 22 | this.toolbar = tbar; 23 | ensureToolBarMenuContainer(); 24 | GGridBagConstraints gbc = new GGridBagConstraints(); 25 | gbc.gridx = 0; 26 | gbc.gridy = 2; 27 | gbc.weightx = 1; 28 | gbc.weighty = 0; 29 | gbc.fill = gbc.HORIZONTAL; 30 | toolbarMenuContainer.add(tbar, gbc); 31 | } 32 | 33 | public void setToolbarLogo(GComponent logo) 34 | { 35 | GGridBagConstraints gbc = new GGridBagConstraints(); 36 | gbc.gridx = 1; 37 | gbc.gridy = 2; 38 | gbc.weightx = 0; 39 | gbc.weighty = 0; 40 | gbc.fill = gbc.BOTH; 41 | Objects.nonNull(toolbar); 42 | toolbarMenuContainer.add(logo, gbc); 43 | } 44 | 45 | public GToolBar getGToolBar() 46 | { 47 | return toolbar; 48 | } 49 | 50 | public GMenuBar getGMenuBar() 51 | { 52 | return menubar; 53 | } 54 | 55 | public void setGMenuBar(GMenuBar mbar) 56 | { 57 | ensureToolBarMenuContainer(); 58 | GGridBagConstraints gbc = new GGridBagConstraints(); 59 | gbc.gridx = 0; 60 | gbc.gridy = 1; 61 | gbc.weightx = 1; 62 | gbc.weighty = 0; 63 | toolbarMenuContainer.add(mbar, gbc); 64 | menubar = mbar; 65 | } 66 | 67 | private void ensureToolBarMenuContainer() 68 | { 69 | if(toolbarMenuContainer == null) 70 | { 71 | GComponent cp = getContentPane(); 72 | remove(cp); 73 | toolbarMenuContainer = new GPanel(); 74 | toolbarMenuContainer.setLayout(new GGridBagLayout()); 75 | GUtilities.insertClassNameBefore(toolbarMenuContainer.getPeer(), "toolbarMenuContainer"); 76 | _add(toolbarMenuContainer, GBorderLayout.CENTER); 77 | GGridBagConstraints gbc = new GGridBagConstraints(); 78 | gbc.gridx = 0; 79 | gbc.gridy = 3; 80 | gbc.gridwidth = 2; 81 | gbc.weightx = 0; 82 | gbc.weighty = 1; 83 | gbc.fill = gbc.BOTH; 84 | toolbarMenuContainer.add(cp, gbc); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GIcon.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GIcon 4 | { 5 | String getURL(); 6 | 7 | int getIconWidth(); 8 | 9 | int getIconHeight(); 10 | } 11 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GImageIcon.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPlatform; 4 | import de.exware.gplatform.element.GPImageElement; 5 | 6 | public class GImageIcon implements GIcon 7 | { 8 | private String url; 9 | private int w; 10 | private int h; 11 | 12 | public GImageIcon(String url, int w, int h) 13 | { 14 | this.url = url; 15 | this.w = w; 16 | this.h = h; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object obj) 21 | { 22 | boolean eq = obj == this; 23 | if (eq == false && obj instanceof GImageIcon) 24 | { 25 | GImageIcon other = (GImageIcon) obj; 26 | eq = this.url.equals(other.url) && w == other.w && h == other.h; 27 | } 28 | return eq; 29 | } 30 | 31 | @Override 32 | public int hashCode() 33 | { 34 | return url.hashCode(); 35 | } 36 | 37 | 38 | @Override 39 | public String getURL() 40 | { 41 | return url; 42 | } 43 | 44 | @Override 45 | public int getIconWidth() 46 | { 47 | return w; 48 | } 49 | 50 | @Override 51 | public int getIconHeight() 52 | { 53 | return h; 54 | } 55 | 56 | static GPImageElement createImageElement(GIcon icon) 57 | { 58 | GPImageElement img = GPlatform.getDoc().createImageElement(); 59 | img.setSrc(icon.getURL()); 60 | img.setWidth(icon.getIconWidth()); 61 | img.setHeight(icon.getIconHeight()); 62 | return img; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GListCellRenderer.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GListCellRenderer 4 | { 5 | /** 6 | * Im Gegensatz zur originalen Implementierung muss hier immer eine neue Komponente geliefert werden. 7 | * @param value 8 | * @param selected 9 | * @param value2 10 | * @return 11 | */ 12 | public GComponent getListCellRendererComponent(GList list, T value, boolean selected); 13 | } 14 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GListModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.swing.event.GListDataListener; 4 | 5 | public interface GListModel 6 | { 7 | public int getSize(); 8 | 9 | public T getElementAt(int index); 10 | 11 | int indexOf(T el); 12 | 13 | void addListDataListener(GListDataListener l); 14 | 15 | void removeListDataListener(GListDataListener l); 16 | } 17 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GListSelectionModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.swing.event.GListSelectionListener; 4 | 5 | public interface GListSelectionModel 6 | { 7 | public static final int SINGLE_SELECTION = 0; 8 | public static final int MULTIPLE_INTERVAL_SELECTION = 2; 9 | 10 | void addListSelectionListener(GListSelectionListener listener); 11 | 12 | void removeListSelectionListener(GListSelectionListener listener); 13 | 14 | void setSelectionMode(int selectionMode); 15 | 16 | void addSelectionInterval(int from, int to); 17 | void setSelectionInterval(int from, int to); 18 | void clearSelection(); 19 | } 20 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GLookAndFeel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.swing.plaf.GUIDefaults; 4 | 5 | public abstract class GLookAndFeel 6 | { 7 | abstract public GUIDefaults getDefaults(); 8 | abstract public void initialize(); 9 | abstract public void uninitialize(); 10 | abstract public String getName(); 11 | } 12 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GMenu.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.awt.GDimension; 7 | import de.exware.gwtswing.awt.event.GActionEvent; 8 | import de.exware.gwtswing.awt.event.GActionListener; 9 | 10 | public class GMenu extends GMenuItem 11 | { 12 | private List items = new ArrayList<>(); 13 | private GPopupMenu menu; 14 | 15 | public GMenu(String text) 16 | { 17 | super(text); 18 | addActionListener(new GActionListener() 19 | { 20 | @Override 21 | public void actionPerformed(GActionEvent evt) 22 | { 23 | if(menu == null) 24 | { 25 | showPopup(); 26 | } 27 | else 28 | { 29 | menu.setVisible(false); 30 | menu = null; 31 | } 32 | } 33 | }); 34 | } 35 | 36 | @Override 37 | public String toString() 38 | { 39 | return getClass().getName() + "; text=" + getText(); 40 | } 41 | 42 | protected void showPopup() 43 | { 44 | menu = new GPopupMenu() 45 | { 46 | @Override 47 | public void setVisible(boolean visible) 48 | { 49 | super.setVisible(visible); 50 | if(visible == false) 51 | { 52 | menu = null; 53 | } 54 | } 55 | }; 56 | for(int i=0;i getItems() 89 | { 90 | return items; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GMenuBar.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.awt.GGridBagConstraints; 4 | import de.exware.gwtswing.awt.GGridBagLayout; 5 | 6 | public class GMenuBar extends GComponent 7 | { 8 | private GGridBagConstraints gbc = new GGridBagConstraints(); 9 | 10 | public GMenuBar() 11 | { 12 | setLayout(new GGridBagLayout()); 13 | gbc.gridx = 1; 14 | gbc.gridy = 1; 15 | } 16 | 17 | public GMenu add(GMenu menu) 18 | { 19 | super.add(menu, gbc); 20 | gbc.gridx++; 21 | return menu; 22 | } 23 | 24 | @Override 25 | protected void addImpl(GComponent comp, Object constraints, int index) 26 | { 27 | if(constraints != gbc) 28 | { 29 | constraints = gbc; 30 | gbc.gridx++; 31 | } 32 | super.addImpl(comp, constraints, index); 33 | } 34 | 35 | public int getMenuCount() 36 | { 37 | return getComponentCount(); 38 | } 39 | 40 | public GMenu getMenu(int i) 41 | { 42 | return (GMenu) getComponent(i); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GMenuItem.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.awt.GInsets; 4 | 5 | public class GMenuItem extends GButton 6 | { 7 | public GMenuItem(String text) 8 | { 9 | super(); 10 | setText(text); 11 | } 12 | 13 | public GMenuItem(GAction action) 14 | { 15 | super(action); 16 | } 17 | 18 | @Override 19 | public GInsets getPadding() 20 | { 21 | return super.getPadding(); 22 | } 23 | 24 | @Override 25 | protected void fireActionEvent() 26 | { 27 | super.fireActionEvent(); 28 | GComponent parent = this; 29 | while(parent != null && parent instanceof GPopupMenu == false) 30 | { 31 | parent = parent.getParent(); 32 | } 33 | if(parent instanceof GPopupMenu) 34 | { 35 | ((GPopupMenu)parent).setVisible(false); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GMutableComboBoxModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GMutableComboBoxModel extends GComboBoxModel 4 | { 5 | public void addElement( E item ); 6 | 7 | public void removeElement( E obj ); 8 | 9 | public void insertElementAt( E item, int index ); 10 | 11 | public void removeElementAt( int index ); 12 | } 13 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GPanel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.awt.GLayoutManager; 4 | 5 | public class GPanel extends GComponent 6 | { 7 | public GPanel() 8 | { 9 | } 10 | 11 | public GPanel(GLayoutManager layout) { 12 | setLayout(layout); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GPasswordField.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPlatform; 4 | import de.exware.gplatform.element.GPInputElement; 5 | 6 | public class GPasswordField extends GTextField 7 | { 8 | public GPasswordField(String text) 9 | { 10 | super(text); 11 | } 12 | 13 | public GPasswordField(int cols) 14 | { 15 | super(cols); 16 | } 17 | 18 | @Override 19 | protected GPInputElement createInputElement() 20 | { 21 | return GPlatform.getDoc().createPasswordInputElement(); 22 | } 23 | 24 | public char[] getPassword() 25 | { 26 | return getText().toCharArray(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GPopup.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gplatform.GPlatform; 5 | import de.exware.gwtswing.awt.GDimension; 6 | 7 | public class GPopup 8 | { 9 | private GPElement popup; 10 | private GComponent owner; 11 | private GComponent contents; 12 | 13 | GPopup(GComponent owner, GComponent contents, int x, int y) 14 | { 15 | popup = GPlatform.getDoc().createDivElement(); 16 | popup.addClassName("gwts-GPopup"); 17 | // popup.getStyle().setZIndex(Integer.MAX_VALUE); 18 | GDimension dim = contents.getPreferredSize(); 19 | if(x + dim.width > GPlatform.getWin().getClientWidth()) 20 | { 21 | x = GPlatform.getWin().getClientWidth() - dim.width; 22 | } 23 | if(y + dim.height > GPlatform.getWin().getClientHeight()) 24 | { 25 | y = GPlatform.getWin().getClientHeight() - dim.height; 26 | } 27 | if(x < 0) 28 | { 29 | x = 0; 30 | } 31 | if(y < 0) 32 | { 33 | y = 0; 34 | } 35 | popup.getStyle().setLeft(x); 36 | popup.getStyle().setTop(y); 37 | this.owner = owner; 38 | this.contents = contents; 39 | } 40 | 41 | public void hide() 42 | { 43 | popup.removeFromParent(); 44 | } 45 | 46 | public void show() 47 | { 48 | GUtilities.addToWidget(popup, contents); 49 | GPElement body = GPlatform.getDoc().getBody(); 50 | body.appendChild(popup); 51 | GDimension dim = contents.getPreferredSize(); 52 | contents.setBounds(0, 0, dim.getWidth(), dim.getHeight()); 53 | contents.validate(); 54 | popup.getStyle().setWidth(dim.getWidth()); 55 | popup.getStyle().setHeight(dim.getHeight()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GPopupFactory.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public class GPopupFactory 4 | { 5 | private static GPopupFactory instance; 6 | 7 | protected GPopupFactory() 8 | {} 9 | 10 | public static GPopupFactory getSharedInstance() 11 | { 12 | if(instance == null) 13 | { 14 | instance = new GPopupFactory(); 15 | } 16 | return instance; 17 | } 18 | 19 | public GPopup getPopup(GComponent owner, GComponent contents, 20 | int x, int y) throws IllegalArgumentException 21 | { 22 | if(contents == null) 23 | { 24 | throw new IllegalArgumentException("contents must not be null."); 25 | } 26 | GPopup popup = new GPopup(owner,contents,x,y); 27 | return popup; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GPopupMenu.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gwtswing.awt.GColor; 4 | import de.exware.gwtswing.awt.GDimension; 5 | import de.exware.gwtswing.awt.GGridBagConstraints; 6 | import de.exware.gwtswing.awt.GGridBagLayout; 7 | import de.exware.gwtswing.awt.GPoint; 8 | import de.exware.gwtswing.awt.GToolkit; 9 | import de.exware.gwtswing.awt.event.GAWTEvent; 10 | import de.exware.gwtswing.awt.event.GAWTEventListener; 11 | import de.exware.gwtswing.awt.event.GMouseEvent; 12 | import de.exware.gwtswing.swing.border.GBorderFactory; 13 | 14 | public class GPopupMenu extends GComponent 15 | { 16 | private GGridBagConstraints gbc = new GGridBagConstraints(); 17 | private GPopup popup; 18 | private static GPopupMenu visibleMenu; 19 | private static GAWTEventListener awtListener; 20 | private boolean visible; 21 | 22 | public GPopupMenu() 23 | { 24 | if(awtListener == null) 25 | { 26 | awtListener = new GAWTEventListener() 27 | { 28 | @Override 29 | public void eventDispatched(GAWTEvent event) 30 | { 31 | if(visibleMenu != null 32 | && ((GMouseEvent)event).getClickCount() > 0 33 | ) 34 | { 35 | GComponent comp = (GComponent) event.getSource(); 36 | GComponent root = GSwingUtilities.getRoot(comp); 37 | if(root != visibleMenu) 38 | { 39 | visibleMenu.setVisible(false); 40 | } 41 | } 42 | } 43 | }; 44 | GToolkit.getDefaultToolkit().addAWTEventListener(awtListener, GAWTEvent.MOUSE_EVENT_MASK); 45 | } 46 | setLayout(new GGridBagLayout()); 47 | gbc.gridx = 0; 48 | gbc.gridy = 0; 49 | gbc.fill = gbc.HORIZONTAL; 50 | setBorder(GBorderFactory.createLineBorder(GColor.GRAY, 1)); 51 | } 52 | 53 | public void add(GAction action) 54 | { 55 | GMenuItem item = new GMenuItem(action); 56 | add(item); 57 | } 58 | 59 | @Override 60 | protected void addImpl(GComponent comp, Object constraints, int index) 61 | { 62 | constraints = gbc; 63 | gbc.gridy++; 64 | super.addImpl(comp, constraints, index); 65 | } 66 | 67 | @Override 68 | public void setVisible(boolean visible) 69 | { 70 | this.visible = visible; 71 | // super.setVisible(visible); 72 | if(popup != null && visible == false) 73 | { 74 | popup.hide(); 75 | popup = null; 76 | visibleMenu = null; 77 | } 78 | if(visible) 79 | { 80 | fireComponentShown(); 81 | } 82 | else 83 | { 84 | fireComponentHidden(); 85 | } 86 | } 87 | 88 | @Override 89 | public boolean isVisible() 90 | { 91 | return visible; 92 | } 93 | 94 | public void show(GComponent comp, int x, int y) 95 | { 96 | if(visibleMenu != null) 97 | { 98 | visibleMenu.setVisible(false); 99 | } 100 | setVisible(true); 101 | GPoint p = comp.getLocationOnScreen(); 102 | popup = GPopupFactory.getSharedInstance().getPopup(comp, this, p.x + x, p.y + y); 103 | popup.show(); 104 | GSwingUtilities.invokeLater(new Runnable() 105 | { 106 | @Override 107 | public void run() 108 | { 109 | visibleMenu = GPopupMenu.this; 110 | } 111 | }); 112 | } 113 | 114 | @Override 115 | public GDimension getPreferredSize() 116 | { 117 | return super.getPreferredSize(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GProgressBar.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gplatform.GPlatform; 5 | import de.exware.gwtswing.awt.GDimension; 6 | 7 | public class GProgressBar extends GComponent 8 | { 9 | private GPElement valueElement; 10 | private GPElement textElement; 11 | private int min = 0; 12 | private int max = 100; 13 | private int value = 0; 14 | 15 | public GProgressBar() 16 | { 17 | super(); 18 | GPElement el = getPeer(); 19 | valueElement = GPlatform.getDoc().createDivElement(); 20 | el.appendChild(valueElement); 21 | valueElement.getStyle().setWidthInPercent(30); 22 | valueElement.getStyle().setHeightInPercent(100); 23 | valueElement.addClassName("gwts-GProgressBar-indicator"); 24 | textElement = GPlatform.getDoc().createDivElement(); 25 | textElement.getStyle().setProperty("textAlign", "center"); 26 | textElement.getStyle().setWidthInPercent(100); 27 | el.appendChild(textElement); 28 | setPreferredSize(new GDimension(100, new GLabel("Hallo").getPreferredSize().height + getStyleExtraHeight())); 29 | } 30 | 31 | public GProgressBar(int min, int max) 32 | { 33 | this(); 34 | setMaximum(max); 35 | } 36 | 37 | public void setValue(int value) 38 | { 39 | if(value > max) 40 | { 41 | value = max; 42 | } 43 | this.value = value; 44 | double val = value * 100.0 / max; 45 | valueElement.getStyle().setWidthInPercent((int)val); 46 | } 47 | 48 | public int getValue() 49 | { 50 | return value; 51 | } 52 | 53 | public void setMaximum(int max) 54 | { 55 | this.max = max; 56 | } 57 | 58 | public void setString(String str) 59 | { 60 | textElement.setInnerText(str); 61 | } 62 | 63 | public void setStringPainted(boolean painted) 64 | { 65 | textElement.getStyle().setVisibility(painted ? "visible": "hidden"); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GRadioButton.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gplatform.GPlatform; 5 | import de.exware.gplatform.element.GPInputElement; 6 | import de.exware.gwtswing.awt.GDimension; 7 | 8 | public class GRadioButton extends GAbstractButton 9 | { 10 | private static int count; 11 | private GPElement labelElement; 12 | private GPElement textElement; 13 | boolean selected; 14 | 15 | public GRadioButton(String text) 16 | { 17 | super(createElement()); 18 | getPeer().removeChild(buttonElement); 19 | labelElement = GPlatform.getDoc().createElement("label"); 20 | textElement = GPlatform.getDoc().createDivElement(); 21 | getPeer().appendChild(labelElement); 22 | labelElement.appendChild(buttonElement); 23 | labelElement.appendChild(textElement); 24 | setText(text); 25 | } 26 | 27 | private static GPInputElement createElement() 28 | { 29 | GPInputElement el = GPlatform.getDoc().createRadioInputElement("__internal_" + count++); 30 | return el; 31 | } 32 | 33 | void setButtonGroup(String name) 34 | { 35 | buttonElement.setAttribute("name", name); 36 | } 37 | 38 | @Override 39 | public void setText(String text) 40 | { 41 | textElement.setInnerHTML(text); 42 | setCachedPreferredSize(null); 43 | } 44 | 45 | @Override 46 | public boolean isSelected() 47 | { 48 | return selected; 49 | } 50 | 51 | @Override 52 | public void setSelected(boolean sel) 53 | { 54 | selected = sel; 55 | buttonElement.setChecked(sel); 56 | buttonElement.setDefaultChecked(sel); 57 | } 58 | 59 | @Override 60 | public void setEnabled(boolean enabled) 61 | { 62 | super.setEnabled(enabled); 63 | buttonElement.setDisabled(!enabled); 64 | } 65 | 66 | @Override 67 | public void validate() 68 | { 69 | super.validate(); 70 | //Ugly Workaround for Radio Buttons, that wont display as selected, if 71 | //the RadioButton is not on a visible panel. 72 | setSelected(isSelected()); 73 | } 74 | 75 | @Override 76 | public String getText() 77 | { 78 | return textElement.getInnerHTML(); 79 | } 80 | 81 | @Override 82 | public GDimension getPreferredSize() 83 | { 84 | GDimension dim = getCachedPreferredSize(); 85 | if(dim == null) 86 | { 87 | GPElement div = GUtilities.getMeasureElement(); 88 | dim = new GDimension(0, 0); 89 | GPElement clone = getPeer().cloneNode(true); 90 | clone.getStyle().clearWidth(); 91 | clone.getStyle().clearHeight(); 92 | div.appendChild(clone); 93 | GPElement label = clone.getChild(0); 94 | GPElement radio = label.getChild(0); 95 | GPElement text = label.getChild(1); 96 | dim.width = radio.getOffsetWidth() + text.getOffsetWidth(); 97 | dim.height = label.getOffsetHeight() > text.getOffsetHeight() ? label.getOffsetHeight() : text.getOffsetHeight(); 98 | div.removeChild(clone); 99 | setCachedPreferredSize(dim); 100 | } 101 | return dim; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GRepaintManager.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | 8 | public class GRepaintManager 9 | { 10 | private static Set containerToLayout = new HashSet<>(); 11 | private static boolean layoutScheduled; 12 | private static long start; 13 | 14 | public static void revalidate(GComponent container) 15 | { 16 | if(containerToLayout.contains(container) == false) 17 | { 18 | containerToLayout.add(container); 19 | } 20 | if(layoutScheduled == false) 21 | { 22 | layoutScheduled = true; 23 | GSwingUtilities.invokeLater(new Runnable() 24 | { 25 | @Override 26 | public void run() 27 | { 28 | start = System.currentTimeMillis(); 29 | layoutScheduled = false; 30 | List list = new ArrayList(containerToLayout); 31 | containerToLayout.clear(); 32 | for(int i=0;i list) 47 | { 48 | GComponent c = comp.getParent(); 49 | while(c != null) 50 | { 51 | if(list.contains(c)) 52 | { 53 | return true; 54 | } 55 | c = c.getParent(); 56 | } 57 | return false; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GSlider.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gplatform.GPlatform; 7 | import de.exware.gplatform.element.GPRangeElement; 8 | import de.exware.gplatform.event.GPEvent; 9 | import de.exware.gplatform.event.GPEventListener; 10 | import de.exware.gwtswing.awt.GDimension; 11 | import de.exware.gwtswing.swing.event.GChangeEvent; 12 | import de.exware.gwtswing.swing.event.GChangeListener; 13 | 14 | public class GSlider extends GComponent implements GSwingConstants 15 | { 16 | private int orientation; 17 | private List changeListeners; 18 | 19 | public GSlider() 20 | { 21 | this(HORIZONTAL, 0, 100, 50); 22 | } 23 | 24 | public GSlider(int orientation) 25 | { 26 | this(orientation, 0, 100, 50); 27 | } 28 | 29 | public GSlider(int min, int max) 30 | { 31 | this(HORIZONTAL, min, max, (min + max) / 2); 32 | } 33 | 34 | public GSlider(int min, int max, int value) 35 | { 36 | this(HORIZONTAL, min, max, value); 37 | } 38 | 39 | public GSlider(int orientation, int min, int max, int value) 40 | { 41 | super(GPlatform.getDoc().createRangeElement()); 42 | setOrientation(orientation); 43 | setMinimum(min); 44 | setMaximum(max); 45 | setValue(value); 46 | GPRangeElement range = (GPRangeElement) getPeer(); 47 | range.enabledEvents(GPEvent.Type.ONCHANGE); 48 | range.setEventListener(new GPEventListener() 49 | { 50 | @Override 51 | public void onBrowserEvent(GPEvent event) 52 | { 53 | fireStateChanged(); 54 | } 55 | }); 56 | } 57 | 58 | public void addChangeListener(GChangeListener l) 59 | { 60 | if(changeListeners == null) 61 | { 62 | changeListeners = new ArrayList<>(); 63 | } 64 | if(changeListeners.contains(l) == false) 65 | { 66 | changeListeners.add(l); 67 | } 68 | } 69 | 70 | private void fireStateChanged() 71 | { 72 | GChangeEvent event = new GChangeEvent(this); 73 | for(int i=0;changeListeners != null && i < changeListeners.size();i++) 74 | { 75 | changeListeners.get(i).stateChanged(event); 76 | } 77 | } 78 | 79 | public int getValue() 80 | { 81 | GPRangeElement range = (GPRangeElement) getPeer(); 82 | return range.getValueInt(); 83 | } 84 | 85 | public void setMinimum(int min) 86 | { 87 | GPRangeElement range = (GPRangeElement) getPeer(); 88 | range.setMinimum(min); 89 | } 90 | 91 | public void setMaximum(int min) 92 | { 93 | GPRangeElement range = (GPRangeElement) getPeer(); 94 | range.setMaximum(min); 95 | } 96 | 97 | public void setValue(int min) 98 | { 99 | GPRangeElement range = (GPRangeElement) getPeer(); 100 | range.setValue(min); 101 | } 102 | 103 | private void setOrientation(int orientation) 104 | { 105 | this.orientation = orientation; 106 | GPRangeElement range = (GPRangeElement) getPeer(); 107 | if(orientation == VERTICAL) 108 | { 109 | range.addClassName("gwts-GSlider-vertical"); 110 | range.setAttribute("orient", "vertical"); 111 | GDimension dim = new GDimension(20, 200); 112 | setPreferredSize(dim); 113 | } 114 | else 115 | { 116 | range.removeClassName("gwts-GSlider-vertical"); 117 | range.setAttribute("orient", ""); 118 | GDimension dim = new GDimension(200, 20); 119 | setPreferredSize(dim); 120 | } 121 | } 122 | 123 | public int getOrientation() 124 | { 125 | return orientation; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GSwingConstants.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | public interface GSwingConstants 4 | { 5 | public static final int CENTER = 0; 6 | public static final int TOP = 1; 7 | public static final int LEFT = 2; 8 | public static final int BOTTOM = 3; 9 | public static final int RIGHT = 4; 10 | 11 | public static final int HORIZONTAL = 0; 12 | public static final int VERTICAL = 1; 13 | } 14 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GSwingUtilities.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.timer.AbstractGPTimerTask; 4 | import de.exware.gplatform.timer.GPTimer; 5 | import de.exware.gwtswing.awt.GPoint; 6 | import de.exware.gwtswing.awt.GWindow; 7 | import de.exware.gwtswing.awt.event.GMouseEvent; 8 | 9 | public class GSwingUtilities 10 | { 11 | public static GWindow getWindowAncestor(GComponent comp) 12 | { 13 | GWindow window = null; 14 | GComponent c = comp.getTopLevelAncestor(); 15 | if(c instanceof GWindow) 16 | { 17 | window = (GWindow) c; 18 | } 19 | return window; 20 | } 21 | 22 | public static GPoint convertPoint(GComponent source, int x, int y, GComponent target) 23 | { 24 | if(source != target) 25 | { 26 | GPoint p = source.getLocationOnScreen(); 27 | x = p.x + x; 28 | y = p.y + y; 29 | p = target.getLocationOnScreen(); 30 | x = x - p.x; 31 | y = y - p.y; 32 | } 33 | return new GPoint(x,y); 34 | } 35 | 36 | public static void invokeLater(final Runnable runner) 37 | { 38 | GPTimer timer = GPTimer.createInstance(); 39 | timer.schedule(new AbstractGPTimerTask() 40 | { 41 | 42 | @Override 43 | public void execute() 44 | { 45 | runner.run(); 46 | } 47 | }, 10); 48 | } 49 | 50 | public static boolean isRightMouseButton(GMouseEvent evt) 51 | { 52 | return evt.getButton() == GMouseEvent.BUTTON3; 53 | } 54 | 55 | public static boolean isLeftMouseButton(GMouseEvent evt) 56 | { 57 | return evt.getButton() == GMouseEvent.BUTTON1; 58 | } 59 | 60 | public static GComponent getRoot(GComponent parent) 61 | { 62 | return parent.getTopLevelAncestor(); 63 | } 64 | 65 | public static void updateComponentTreeUI(GComponent c) 66 | { 67 | if(c != null) 68 | { 69 | c.updateUI(); 70 | for(GComponent component : c.getComponents()) 71 | { 72 | updateComponentTreeUI(component); 73 | } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GTextArea.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gplatform.GPlatform; 5 | import de.exware.gplatform.element.GPTextAreaElement; 6 | import de.exware.gwtswing.awt.GDimension; 7 | import de.exware.gwtswing.awt.GFont; 8 | 9 | public class GTextArea extends GTextComponent 10 | { 11 | protected GPTextAreaElement textElement; 12 | 13 | public GTextArea(String text) 14 | { 15 | this(text, 4, 20); 16 | } 17 | 18 | public GTextArea(String text, int rows, int columns) 19 | { 20 | super(); 21 | textElement = GPlatform.getDoc().createTextAreaElement(); 22 | setPeer(textElement); 23 | setClassNames(textElement, ""); 24 | // getPeer().appendChild(textElement); 25 | textElement.setCols(columns); 26 | textElement.setRows(rows); 27 | setFont(textElement, getFont()); 28 | setText(text); 29 | } 30 | 31 | @Override 32 | public void setEnabled(boolean enabled) 33 | { 34 | super.setEnabled(enabled); 35 | textElement.setDisabled(!enabled); 36 | } 37 | 38 | @Override 39 | public void setBounds(int x, int y, int width, int height) 40 | { 41 | super.setBounds(x, y, width, height); 42 | // width -= getStyleExtraWidth(); 43 | // height -= getStyleExtraHeight(); 44 | // if(width < 0) width = 0; 45 | // if(height < 0) height = 0; 46 | // Style style = textElement.getStyle(); 47 | // style.setLeft(x, Unit.PX); 48 | // style.setTop(y, Unit.PX); 49 | // style.setWidth(width, Unit.PX); 50 | // style.setHeight(height, Unit.PX); 51 | } 52 | 53 | @Override 54 | public void setFont(GFont font) 55 | { 56 | super.setFont(font); 57 | setFont(textElement, font); 58 | } 59 | 60 | @Override 61 | public String getText() 62 | { 63 | return textElement.getValue(); 64 | } 65 | 66 | @Override 67 | public void setText(String text) 68 | { 69 | if(text == null) 70 | { 71 | text = ""; 72 | } 73 | textElement.setValue(text); 74 | setCachedPreferredSize(null); 75 | } 76 | 77 | @Override 78 | public GDimension getPreferredSize() 79 | { 80 | GDimension dim = getCachedPreferredSize(); 81 | if(dim == null) 82 | { 83 | GPElement div = GUtilities.getMeasureElement(); 84 | GPTextAreaElement span = GPlatform.getDoc().createTextAreaElement(); 85 | span.setCols(textElement.getCols()); 86 | span.setRows(textElement.getRows()); 87 | span.setValue(getText()); 88 | double fontSize = getFont().getSize2D(); 89 | String family = getFont().getFamily(); 90 | span.getStyle().setFontSize((float) fontSize); 91 | span.getStyle().setProperty("fontFamily", family); 92 | // span.setSize(textElement.getStyle().getWidth()); 93 | div.appendChild(span); 94 | int w = span.getOffsetWidth() + getStyleExtraWidth(); 95 | int h = span.getOffsetHeight() + getStyleExtraHeight(); 96 | div.removeChild(span); 97 | dim = new GDimension(w, h); 98 | setCachedPreferredSize(dim); 99 | } 100 | return dim; 101 | } 102 | 103 | // @Override 104 | // public GDimension getPreferredSize() 105 | // { 106 | // Element peer = getPeer(); 107 | // PixelStyle pstyle = GUtilities.getComputedStyle(peer); 108 | // DivElement div = GUtilities.getMeasureElement(); 109 | // InputElement span = Document.get().createTextInputElement(); 110 | // span.setValue(getText()); 111 | // double fontSize = pstyle.getFontSize(); 112 | // span.getStyle().setFontSize(fontSize, Unit.PX); 113 | // span.setSize(5); 114 | // div.appendChild(span); 115 | // int w = span.getOffsetWidth() + getStyleExtraWidth(pstyle); 116 | // int h = span.getOffsetHeight() + getStyleExtraHeight(pstyle); 117 | // div.removeChild(span); 118 | // return new GDimension(w, h); 119 | // } 120 | 121 | 122 | @Override 123 | public int getCaretPosition() 124 | { 125 | return textElement.getPropertyInt("selectionStart"); 126 | } 127 | 128 | @Override 129 | public void setCaretPosition(int pos) 130 | { 131 | textElement.setPropertyInt("selectionStart", pos); 132 | } 133 | 134 | @Override 135 | public void select(int selectionStart, int selectionEnd) 136 | { 137 | } 138 | 139 | @Override 140 | public void requestFocus() 141 | { 142 | GSwingUtilities.invokeLater(new Runnable() 143 | { 144 | @Override 145 | public void run() 146 | { 147 | textElement.focus(); 148 | } 149 | }); 150 | } 151 | 152 | @Override 153 | public int getSelectionStart() 154 | { 155 | return textElement.getPropertyInt("selectionStart"); 156 | } 157 | 158 | @Override 159 | public int getSelectionEnd() 160 | { 161 | return textElement.getPropertyInt("selectionEnd"); 162 | } 163 | 164 | @Override 165 | public boolean hasFocus() 166 | { 167 | return textElement.hasFocus(); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GTextComponent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | abstract public class GTextComponent extends GComponent 4 | { 5 | public GTextComponent() 6 | { 7 | } 8 | 9 | abstract public String getText(); 10 | 11 | abstract public void setText(String text); 12 | 13 | abstract public int getCaretPosition(); 14 | abstract public void setCaretPosition(int pos); 15 | 16 | abstract public int getSelectionStart(); 17 | abstract public int getSelectionEnd(); 18 | 19 | 20 | abstract public void select(int selectionStart, int selectionEnd); 21 | } 22 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GToggleButton.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing; 2 | 3 | import de.exware.gplatform.GPElement; 4 | import de.exware.gwtswing.awt.GColor; 5 | import de.exware.gwtswing.awt.GDimension; 6 | import de.exware.gwtswing.awt.GInsets; 7 | 8 | public class GToggleButton extends GAbstractButton 9 | { 10 | private GPElement img; 11 | private GIcon icon; 12 | private boolean selected; 13 | 14 | public GToggleButton() 15 | { 16 | this(""); 17 | } 18 | 19 | public GToggleButton(GAction action) 20 | { 21 | this(""); 22 | setAction(action); 23 | } 24 | 25 | public GToggleButton(String text) 26 | { 27 | setText(text); 28 | } 29 | 30 | @Override 31 | protected void fireActionEvent() 32 | { 33 | if(isEnabled()) 34 | { 35 | setSelected(!selected); 36 | } 37 | super.fireActionEvent(); 38 | } 39 | 40 | @Override 41 | public void setBackground(GColor col) 42 | { 43 | super.setBackground(col); 44 | } 45 | 46 | @Override 47 | public void setEnabled(boolean enabled) 48 | { 49 | super.setEnabled(enabled); 50 | } 51 | 52 | public GToggleButton(GIcon icon) 53 | { 54 | this((String)null); 55 | setIcon(icon); 56 | } 57 | 58 | @Override 59 | public String getText() 60 | { 61 | GPElement peer = getPeer(); 62 | return peer.getInnerText(); 63 | } 64 | 65 | @Override 66 | public void setText(String text) 67 | { 68 | GPElement peer = getPeer(); 69 | peer.setInnerHTML(text); 70 | if (img != null) 71 | { 72 | getPeer().insertFirst(img); 73 | } 74 | setCachedPreferredSize(null); 75 | } 76 | 77 | @Override 78 | public void setIcon(GIcon icon) 79 | { 80 | this.icon = icon; 81 | GPElement peer = getPeer(); 82 | if (icon == null) 83 | { 84 | if (img != null) 85 | { 86 | img.removeFromParent(); 87 | img = null; 88 | } 89 | } 90 | else 91 | { 92 | GPElement old = img; 93 | img = GImageIcon.createImageElement(icon); 94 | if (old != null && old.getParentElement() != null) 95 | { 96 | peer.replaceChild(img, old); 97 | } 98 | else 99 | { 100 | peer.insertFirst(img); 101 | } 102 | } 103 | setCachedPreferredSize(null); 104 | } 105 | 106 | @Override 107 | public GInsets getPadding() 108 | { 109 | return super.getPadding(); 110 | } 111 | 112 | @Override 113 | public GDimension getPreferredSize() 114 | { 115 | GDimension dim = getCachedPreferredSize(); 116 | if(dim == null) 117 | { 118 | if (img != null) 119 | { 120 | img.removeFromParent(); 121 | } 122 | dim = super.getPreferredSize(); 123 | dim.width ++; 124 | if (img != null) 125 | { 126 | getPeer().insertFirst(img); 127 | dim.width += icon.getIconWidth(); 128 | int extraheight = getStyleExtraHeight(); 129 | dim.height = dim.height > icon.getIconHeight() ? dim.height : icon.getIconHeight() + extraheight; 130 | } 131 | } 132 | return dim; 133 | } 134 | 135 | @Override 136 | public void setSelected(boolean sel) 137 | { 138 | super.setSelected(sel); 139 | selected = sel; 140 | if(selected) 141 | { 142 | getPeer().addClassName("gwts-GToggleButton-active"); 143 | } 144 | else 145 | { 146 | getPeer().removeClassName("gwts-GToggleButton-active"); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/GToolBar.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006 eXware 3 | * All rights reserved. 4 | * 5 | * This software is the confidential and proprietary information of 6 | * eXware ("Confidential Information"). You shall not disclose such 7 | * Confidential Information and shall use it only in accordance with 8 | * the terms of the license agreement you entered into with eXware. 9 | */ 10 | package de.exware.gwtswing.swing; 11 | 12 | 13 | import de.exware.gwtswing.awt.GGridBagConstraints; 14 | import de.exware.gwtswing.awt.GGridBagLayout; 15 | 16 | /** 17 | * This Toolbar allows to add groups. Toolbar elements can than be added to a 18 | * group, which allows better automated sorting of the toolbar elements. 19 | */ 20 | public class GToolBar extends GComponent 21 | { 22 | private GGridBagConstraints gbc; 23 | 24 | public GToolBar() 25 | { 26 | gbc = new GGridBagConstraints(); 27 | setLayout(new GGridBagLayout()); 28 | } 29 | 30 | public GGridBagConstraints getConstraints() 31 | { 32 | return gbc; 33 | } 34 | 35 | @Override 36 | protected void addImpl(GComponent comp, Object constraints, int index) 37 | { 38 | super.addImpl(comp, gbc, index); 39 | gbc.gridx++; 40 | if(index < getComponentCount()) 41 | { 42 | GGridBagLayout gbl = (GGridBagLayout) getLayout(); 43 | gbc = new GGridBagConstraints(); 44 | for(int i=0;i minIndex ? maxIndex : minIndex; 22 | } 23 | 24 | public int getIndex0() 25 | { 26 | return minIndex; 27 | } 28 | 29 | public int getIndex1() 30 | { 31 | return maxIndex; 32 | } 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GListDataListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public interface GListDataListener 4 | { 5 | void intervalAdded(GListDataEvent e); 6 | 7 | void intervalRemoved(GListDataEvent e); 8 | 9 | void contentsChanged(GListDataEvent e); 10 | } -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GListSelectionEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | import de.exware.gwtswing.util.GEventObject; 4 | 5 | public class GListSelectionEvent extends GEventObject 6 | { 7 | public GListSelectionEvent(Object source) 8 | { 9 | super(source); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GListSelectionListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public interface GListSelectionListener 4 | { 5 | void valueChanged(GListSelectionEvent e); 6 | } 7 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GPropertyChangeEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | import de.exware.gwtswing.util.GEventObject; 4 | 5 | public class GPropertyChangeEvent extends GEventObject 6 | { 7 | private String property; 8 | private Object value; 9 | 10 | public GPropertyChangeEvent(Object source,String property, Object value) 11 | { 12 | super(source); 13 | this.property = property; 14 | this.value = value; 15 | } 16 | 17 | public String getProperty() 18 | { 19 | return property; 20 | } 21 | 22 | public Object getValue() 23 | { 24 | return value; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GPropertyChangeListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public interface GPropertyChangeListener 4 | { 5 | void propertyChanged(GPropertyChangeEvent evt); 6 | } 7 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTabAdapter.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public class GTabAdapter 4 | implements GTabListener 5 | { 6 | @Override 7 | public void tabActivated(GTabEvent evt) 8 | { 9 | } 10 | 11 | @Override 12 | public void tabAdded(GTabEvent evt) 13 | { 14 | } 15 | 16 | @Override 17 | public void tabRemoved(GTabEvent evt) 18 | { 19 | } 20 | 21 | @Override 22 | public void checkTabClosingAllowed(GTabEvent tevt) 23 | { 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTabEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006 eXware 3 | * All rights reserved. 4 | * 5 | * This software is the confidential and proprietary information of 6 | * eXware ("Confidential Information"). You shall not disclose such 7 | * Confidential Information and shall use it only in accordance with 8 | * the terms of the license agreement you entered into with eXware. 9 | */ 10 | package de.exware.gwtswing.swing.event; 11 | 12 | import de.exware.gwtswing.swing.GComponent; 13 | import de.exware.gwtswing.util.GEventObject; 14 | 15 | /** 16 | * 17 | */ 18 | public class GTabEvent extends GEventObject 19 | { 20 | private GComponent tab; 21 | private GComponent tabbedComponent; 22 | /** 23 | * This is used to check that every Listener has voted for closing or against it. 24 | */ 25 | private int tabListenerCount; 26 | private int votes; 27 | private CloseState closeState = CloseState.IN_PROGRESS; 28 | 29 | public enum CloseState 30 | { 31 | CANCEL 32 | , IN_PROGRESS 33 | , CLOSE 34 | } 35 | 36 | /** 37 | * @param source 38 | * @param id 39 | */ 40 | public GTabEvent(Object source, GComponent tab, GComponent tabbedComponent) 41 | { 42 | super(source); 43 | this.tab = tab; 44 | this.tabbedComponent = tabbedComponent; 45 | } 46 | 47 | public GComponent getTab() 48 | { 49 | return this.tab; 50 | } 51 | 52 | public GComponent getTabbedComponent() 53 | { 54 | return this.tabbedComponent; 55 | } 56 | 57 | public void setListenerCount(int size) 58 | { 59 | tabListenerCount = size; 60 | } 61 | 62 | public CloseState getCloseState() 63 | { 64 | return closeState; 65 | } 66 | 67 | public void allowClose(boolean allow) 68 | { 69 | votes++; 70 | if(false == allow) 71 | { 72 | closeState = CloseState.CANCEL; 73 | } 74 | if(votes == tabListenerCount && closeState == CloseState.IN_PROGRESS) 75 | { 76 | closeState = CloseState.CLOSE; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTabListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2006 eXware 3 | * All rights reserved. 4 | * 5 | * This software is the confidential and proprietary information of 6 | * eXware ("Confidential Information"). You shall not disclose such 7 | * Confidential Information and shall use it only in accordance with 8 | * the terms of the license agreement you entered into with eXware. 9 | */ 10 | package de.exware.gwtswing.swing.event; 11 | 12 | /** 13 | * GTabListeners will be notified on any changes made to the Tabs of an ETabbedPane. 14 | */ 15 | public interface GTabListener 16 | { 17 | /** 18 | * Signals the activation of a Tab. 19 | * @param evt 20 | */ 21 | public void tabActivated(GTabEvent evt); 22 | 23 | /** 24 | * Called if a new Tab is added. 25 | * @param evt 26 | */ 27 | public void tabAdded(GTabEvent evt); 28 | 29 | /** 30 | * Called if a has been removed. 31 | * @param evt 32 | */ 33 | public void tabRemoved(GTabEvent evt); 34 | 35 | /** 36 | * Is called if an Tab is about to be closed. Listeners may avoid closing 37 | * by calling tevt.allowClosed(boolean alowed); 38 | * @param evt 39 | * @return 40 | */ 41 | public void checkTabClosingAllowed(GTabEvent tevt); 42 | } 43 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTableModelEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | import de.exware.gwtswing.swing.table.GTableModel; 4 | import de.exware.gwtswing.util.GEventObject; 5 | 6 | public class GTableModelEvent 7 | extends GEventObject 8 | { 9 | public static final int INSERT = 0; 10 | public static final int UPDATE = 1; 11 | public static final int DELETE = 2; 12 | public static final int HEADER_ROW = -1; 13 | private int type; 14 | private int firstRow; 15 | private int lastRow; 16 | private int column; 17 | 18 | public GTableModelEvent(GTableModel source) 19 | { 20 | this(source, 0, Integer.MAX_VALUE, 0, UPDATE); 21 | } 22 | 23 | public GTableModelEvent(GTableModel source, int row) 24 | { 25 | this(source, row, row, 0, UPDATE); 26 | } 27 | 28 | public GTableModelEvent(GTableModel source, int firstRow, int lastRow, int column, int type) 29 | { 30 | super(source); 31 | this.type = type; 32 | this.firstRow = firstRow; 33 | this.lastRow = lastRow; 34 | this.column = column; 35 | } 36 | 37 | public int getType() 38 | { 39 | return type; 40 | } 41 | 42 | public int getFirstRow() 43 | { 44 | return firstRow; 45 | } 46 | 47 | public int getLastRow() 48 | { 49 | return lastRow; 50 | } 51 | 52 | public int getColumn() 53 | { 54 | return column; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTableModelListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | 4 | public interface GTableModelListener 5 | { 6 | public void tableChanged(GTableModelEvent evt); 7 | } 8 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTreeModelEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | import de.exware.gwtswing.swing.tree.GTreePath; 4 | import de.exware.gwtswing.util.GEventObject; 5 | 6 | public class GTreeModelEvent extends GEventObject 7 | { 8 | private GTreePath parent; 9 | 10 | public GTreeModelEvent(Object source) 11 | { 12 | super(source); 13 | } 14 | 15 | public GTreeModelEvent(Object source, GTreePath parent, int[] children) 16 | { 17 | super(source); 18 | this.parent = parent; 19 | } 20 | 21 | public GTreePath getTreePath() 22 | { 23 | return parent; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTreeModelListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public interface GTreeModelListener 4 | { 5 | void treeStructureChanged(GTreeModelEvent e); 6 | 7 | void treeNodesChanged(GTreeModelEvent e); 8 | } 9 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTreeSelectionEvent.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | import de.exware.gwtswing.swing.tree.GTreePath; 4 | import de.exware.gwtswing.util.GEventObject; 5 | 6 | public class GTreeSelectionEvent extends GEventObject 7 | { 8 | private GTreePath path; 9 | 10 | public GTreeSelectionEvent(Object source, GTreePath treePath) 11 | { 12 | super(source); 13 | path = treePath; 14 | } 15 | 16 | public GTreePath getPath() 17 | { 18 | return path; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/event/GTreeSelectionListener.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.event; 2 | 3 | public interface GTreeSelectionListener 4 | { 5 | void valueChanged(GTreeSelectionEvent e); 6 | } 7 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/plaf/ComponentUI.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.plaf; 2 | 3 | import de.exware.gwtswing.swing.GComponent; 4 | 5 | public abstract class ComponentUI 6 | { 7 | 8 | static public ComponentUI createUI(GComponent component) 9 | { 10 | throw new Error("Not implemented."); 11 | } 12 | 13 | protected ComponentUI() {}; 14 | 15 | abstract public void installUI(GComponent c); 16 | 17 | abstract public void uninstallUI(GComponent c); 18 | } 19 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/plaf/GUIDefaults.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.plaf; 2 | 3 | import de.exware.gwtswing.swing.GComponent; 4 | 5 | public abstract class GUIDefaults 6 | { 7 | abstract public ComponentUI getUI(GComponent component); 8 | } 9 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/table/GAbstractTableModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.table; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.swing.event.GTableModelEvent; 7 | import de.exware.gwtswing.swing.event.GTableModelListener; 8 | 9 | abstract public class GAbstractTableModel implements GTableModel 10 | { 11 | private List listeners; 12 | 13 | @Override 14 | public String getColumnName(int col) 15 | { 16 | return "" + col; 17 | } 18 | 19 | @Override 20 | public Class getColumnClass(int col) 21 | { 22 | return Object.class; 23 | } 24 | 25 | @Override 26 | public void addTableModelListener(GTableModelListener listener) 27 | { 28 | if(listeners == null) 29 | { 30 | listeners = new ArrayList<>(); 31 | } 32 | if(listeners.contains(listener) == false) 33 | { 34 | listeners.add(listener); 35 | } 36 | } 37 | 38 | @Override 39 | public void removeTableModelListener(GTableModelListener listener) 40 | { 41 | if(listeners != null) 42 | { 43 | listeners.remove(listener); 44 | } 45 | } 46 | 47 | public void fireTableStructureChanged() 48 | { 49 | fireTableChanged(new GTableModelEvent(this, GTableModelEvent.HEADER_ROW)); 50 | } 51 | 52 | public void fireTableChanged(GTableModelEvent e) 53 | { 54 | if(listeners != null) 55 | { 56 | List listeners = new ArrayList<>(this.listeners); 57 | for(int i=0;listeners != null && i listeners = new ArrayList<>(this.listeners); 67 | GTableModelEvent evt = new GTableModelEvent(this, from, to, 0, GTableModelEvent.INSERT); 68 | for(int i=0;listeners != null && i listeners = new ArrayList<>(this.listeners); 77 | GTableModelEvent evt = new GTableModelEvent(this, from, to, 0, GTableModelEvent.DELETE); 78 | for(int i=0;listeners != null && i listeners = new ArrayList<>(this.listeners); 87 | GTableModelEvent evt = new GTableModelEvent(this, from, to, 0, GTableModelEvent.UPDATE); 88 | for(int i=0;listeners != null && i 7 | { 8 | GComponent getTableCellRendererComponent(GTable table, Object value, 9 | boolean isSelected, boolean hasFocus, 10 | int row, int column); 11 | } 12 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/table/GTableModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.table; 2 | 3 | import de.exware.gwtswing.swing.event.GTableModelListener; 4 | 5 | public interface GTableModel 6 | { 7 | public int getColumnCount(); 8 | public String getColumnName(int col); 9 | public Class getColumnClass(int col); 10 | public int getRowCount(); 11 | public void addTableModelListener(GTableModelListener listener); 12 | public void removeTableModelListener(GTableModelListener listener); 13 | public Object getValueAt(int row, int column); 14 | } -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/table/TableFilterDialog.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.table; 2 | 3 | import de.exware.gwtswing.swing.GDialog; 4 | 5 | public class TableFilterDialog extends GDialog 6 | { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/tree/GDefaultMutableTreeNode.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.tree; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class GDefaultMutableTreeNode implements GMutableTreeNode 7 | { 8 | private List children; 9 | private GTreeNode parent; 10 | private Object userObject; 11 | 12 | public GDefaultMutableTreeNode() 13 | { 14 | } 15 | 16 | public GDefaultMutableTreeNode(Object userObject) 17 | { 18 | this.userObject = userObject; 19 | } 20 | 21 | @Override 22 | // @JsMethod 23 | public String toString() 24 | { 25 | String str = ""; 26 | if(userObject != null) 27 | { 28 | str = userObject.toString(); 29 | } 30 | return str; 31 | } 32 | 33 | @Override 34 | public GTreeNode getChildAt(int childIndex) 35 | { 36 | if(children != null) 37 | { 38 | return children.get(childIndex); 39 | } 40 | return null; 41 | } 42 | 43 | @Override 44 | public int getChildCount() 45 | { 46 | if(children != null) 47 | { 48 | return children.size(); 49 | } 50 | return 0; 51 | } 52 | 53 | @Override 54 | public GTreeNode getParent() 55 | { 56 | return parent; 57 | } 58 | 59 | @Override 60 | public int getIndex(GTreeNode node) 61 | { 62 | if(children != null) 63 | { 64 | return children.indexOf(node); 65 | } 66 | return -1; 67 | } 68 | 69 | @Override 70 | public boolean getAllowsChildren() 71 | { 72 | return false; 73 | } 74 | 75 | @Override 76 | public boolean isLeaf() 77 | { 78 | return children == null; 79 | } 80 | 81 | @Override 82 | public void insert(GMutableTreeNode child, int index) 83 | { 84 | if(children == null) 85 | { 86 | children = new ArrayList<>(); 87 | } 88 | children.add(index, child); 89 | child.setParent(this); 90 | } 91 | 92 | @Override 93 | public void remove(int index) 94 | { 95 | if(children != null) 96 | { 97 | children.remove(index); 98 | } 99 | } 100 | 101 | @Override 102 | public void remove(GMutableTreeNode node) 103 | { 104 | if(children != null) 105 | { 106 | children.remove(node); 107 | } 108 | } 109 | 110 | @Override 111 | public void setUserObject(Object object) 112 | { 113 | userObject = object; 114 | } 115 | 116 | @Override 117 | public void setParent(GMutableTreeNode newParent) 118 | { 119 | parent = newParent; 120 | } 121 | 122 | @Override 123 | public void removeFromParent() 124 | { 125 | if(parent instanceof GMutableTreeNode) 126 | { 127 | ((GMutableTreeNode)parent).remove(this); 128 | } 129 | } 130 | 131 | public Object getUserObject() 132 | { 133 | return userObject; 134 | } 135 | 136 | public void add(GMutableTreeNode node) 137 | { 138 | if(children == null) 139 | { 140 | children = new ArrayList<>(); 141 | } 142 | children.add(node); 143 | node.setParent(this); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/tree/GDefaultTreeCellRenderer.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.tree; 2 | 3 | import de.exware.gwtswing.Constants; 4 | import de.exware.gwtswing.swing.GComponent; 5 | import de.exware.gwtswing.swing.GIcon; 6 | import de.exware.gwtswing.swing.GImageIcon; 7 | import de.exware.gwtswing.swing.GLabel; 8 | import de.exware.gwtswing.swing.GTree; 9 | import de.exware.gwtswing.swing.GUIManager; 10 | import de.exware.gwtswing.swing.GUtilities; 11 | 12 | public class GDefaultTreeCellRenderer implements GTreeCellRenderer 13 | { 14 | private static GIcon folderIcon = new GImageIcon(GUtilities.getResource(Constants.PLUGIN_ID, "/icons/folder.svg"),16,16); 15 | private static GIcon fileIcon = new GImageIcon(GUtilities.getResource(Constants.PLUGIN_ID, "/icons/file.svg"),16,16); 16 | 17 | @Override 18 | public GComponent getTreeCellRendererComponent(GTree tree, Object value, boolean selected, boolean expanded, 19 | boolean leaf, int row, boolean hasFocus) 20 | { 21 | GLabel label = new GLabel(leaf ? fileIcon : folderIcon); 22 | //This line is a hack, because the GWT Compiler removes the toString method if this is not there. 23 | //But only in Production. Development mode is OK??? 24 | label.setText(value == null ? "" : "" + value.getClass()); 25 | label.setText(value == null ? "" : value.toString()); 26 | label.setBackground(null); 27 | if(selected) 28 | { 29 | label.setBackground(GUIManager.getColor(".gwts-GTree-selected/background-color")); 30 | } 31 | return label; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /source/java/de/exware/gwtswing/swing/tree/GDefaultTreeModel.java: -------------------------------------------------------------------------------- 1 | package de.exware.gwtswing.swing.tree; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import de.exware.gwtswing.swing.event.GTreeModelEvent; 7 | import de.exware.gwtswing.swing.event.GTreeModelListener; 8 | 9 | public class GDefaultTreeModel implements GTreeModel 10 | { 11 | private List listeners; 12 | private GTreeNode root; 13 | 14 | public GDefaultTreeModel(GTreeNode root) 15 | { 16 | this.root = root; 17 | } 18 | 19 | @Override 20 | public Object getRoot() 21 | { 22 | return root; 23 | } 24 | 25 | @Override 26 | public Object getChild(Object parent, int index) 27 | { 28 | GTreeNode tn = (GTreeNode) parent; 29 | return tn.getChildAt(index); 30 | } 31 | 32 | @Override 33 | public int getChildCount(Object parent) 34 | { 35 | GTreeNode tn = (GTreeNode) parent; 36 | return tn.getChildCount(); 37 | } 38 | 39 | @Override 40 | public boolean isLeaf(Object node) 41 | { 42 | GTreeNode tn = (GTreeNode) node; 43 | return tn.isLeaf(); 44 | } 45 | 46 | @Override 47 | public void valueForPathChanged(GTreePath path, Object newValue) 48 | { 49 | } 50 | 51 | @Override 52 | public int getIndexOfChild(Object parent, Object child) 53 | { 54 | GTreeNode tn = (GTreeNode) parent; 55 | return tn.getIndex((GTreeNode) child); 56 | } 57 | 58 | @Override 59 | public void addTreeModelListener(GTreeModelListener l) 60 | { 61 | if(listeners == null) 62 | { 63 | listeners = new ArrayList<>(); 64 | } 65 | if(listeners.contains(l) == false) 66 | { 67 | listeners.add(l); 68 | } 69 | } 70 | 71 | @Override 72 | public void removeTreeModelListener(GTreeModelListener l) 73 | { 74 | if(listeners != null) 75 | { 76 | listeners.remove(l); 77 | } 78 | } 79 | 80 | protected void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) 81 | { 82 | if(listeners != null && listeners.size() > 0) 83 | { 84 | GTreeModelEvent evt = new GTreeModelEvent(this); 85 | for(int i=0;i 0) 95 | { 96 | GTreeModelEvent evt = new GTreeModelEvent(this, new GTreePath(path), childIndices); 97 | for(int i=0;i