r387 - in testTreeTooltipSession/trunk: . src src/main src/main/java src/main/java/com src/main/java/com/xduke src/main/java/com/xduke/xswing src/main/java/org src/main/java/org/nuiton src/main/java/org/nuiton/test src/main/java/org/nuiton/test/resources src/main/java/org/nuiton/test/saf
Author: echatellier Date: 2010-03-04 17:06:40 +0100 (Thu, 04 Mar 2010) New Revision: 387 Log: Init commit. Added: testTreeTooltipSession/trunk/pom.xml testTreeTooltipSession/trunk/src/ testTreeTooltipSession/trunk/src/main/ testTreeTooltipSession/trunk/src/main/java/ testTreeTooltipSession/trunk/src/main/java/com/ testTreeTooltipSession/trunk/src/main/java/com/xduke/ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipCell.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipComponent.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipListener.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipManager.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipPopup.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipCell.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipListener.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipCell.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipListener.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipCell.java testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipListener.java testTreeTooltipSession/trunk/src/main/java/org/ testTreeTooltipSession/trunk/src/main/java/org/nuiton/ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTableModel.java testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTreeModel.java testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/CustomTreeFilter.java testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/Main.java testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/TreeFilter.java testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MainApplication.properties testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/SafApplicationContext.java testTreeTooltipSession/trunk/src/main/resources/ Modified: testTreeTooltipSession/trunk/ Property changes on: testTreeTooltipSession/trunk ___________________________________________________________________ Added: svn:ignore + .settings target .classpath .project Added: testTreeTooltipSession/trunk/pom.xml =================================================================== --- testTreeTooltipSession/trunk/pom.xml (rev 0) +++ testTreeTooltipSession/trunk/pom.xml 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.ceric35</groupId> + <artifactId>testtrees</artifactId> + <version>1.0.0-SNAPSHOT</version> + <packaging>jar</packaging> + + <name>TestTrees</name> + <description>TestTrees</description> + <inceptionYear>2010</inceptionYear> + + <licenses> + <license> + <name>GPL</name> + <url>http://www.gnu.org/licenses/gpl.txt</url> + <distribution>repo</distribution> + </license> + </licenses> + + <developers> + <developer> + <id>ceric35</id> + <name>Eric Chatellier</name> + <email>chatellier@codelutin.com</email> + <organization>CodeLutin</organization> + <timezone>+2</timezone> + <roles> + <role>Développeur</role> + </roles> + </developer> + </developers> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputDirectory>UTF-8</project.reporting.outputDirectory> + <maven.compiler.source>1.6</maven.compiler.source> + <maven.compiler.target>1.6</maven.compiler.target> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.1.1</version> + <executions> + <execution> + <goals> + <goal>java</goal> + </goals> + </execution> + </executions> + <configuration> + <mainClass>org.nuiton.test.Main</mainClass> + <classpathScope>runtime</classpathScope> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.11</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>0.9.18</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + <version>5.11</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.swinglabs</groupId> + <artifactId>swingx</artifactId> + <version>1.6</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>net.java.balloontip</groupId> + <artifactId>balloontip</artifactId> + <version>1.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.jdesktop</groupId> + <artifactId>appframework</artifactId> + <version>1.0.3</version> + <scope>compile</scope> + </dependency> + </dependencies> + + <repositories> + <repository> + <id>nuiton.repository</id> + <url>http://maven.nuiton.org/release</url> + </repository> + <repository> + <id>jboss.repository</id> + <url>http://repository.jboss.com/maven2</url> + </repository> + <repository> + <id>maven2-repository.dev.java.net</id> + <url>http://download.java.net/maven/2/</url> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>nuiton.repository</id> + <url>http://maven.nuiton.org/release</url> + </pluginRepository> + </pluginRepositories> +</project> Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipCell.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipCell.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipCell.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import java.awt.*; + +interface DataTipCell { + + boolean isSet(); + + Component getRendererComponent(); + + Rectangle getCellBounds(); + + /** + * 'Null' value for cells (location is outside of any cell bounds). + */ + DataTipCell NONE = new DataTipCell() { + + public boolean isSet() { + return false; + } + + public Component getRendererComponent() { + return null; + } + + public Rectangle getCellBounds() { + return null; + } + + public boolean equals(Object obj) { + return false; + } + + public int hashCode() { + return 0; + } + }; +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipCell.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipComponent.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipComponent.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipComponent.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; + +/** + * Note: It's important to inherit from JToolTip: Mouse events get dispatched to the parent.<br/> + * I do not really know why this is so. At least PopupFactory creates a different type of popup + * if the content is instance of JToolTip. + */ +class DataTipComponent extends JToolTip { + private DataTipCell cell; + private CellRendererPane rendererPane; + private Rectangle withoutBorderRectangle; + private Color backgroundColor; + private boolean isHeavyWeight; + + DataTipComponent(DataTipCell cell, Rectangle withoutBorderRectangle, Color backgroundColor) { + this.cell = cell; + this.withoutBorderRectangle = withoutBorderRectangle; + this.backgroundColor = backgroundColor; + rendererPane = new CellRendererPane(); + add(rendererPane); + setFocusable(false); + setBorder(null); + enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK); + } + + /** + * Overriden, so that Swing does not create a ToolTipUI. + */ + public void updateUI() { + } + + /** + * Overriden to always return false, so that no component ever receives mouse events. + * Instead a mouse press will be caught on the popup's window ancestor, the popup will be hidden and the mouse press redispatched + * to the underlying component. + */ + public boolean contains(int x, int y) { + return isHeavyWeight; + } + + protected void processMouseEvent(MouseEvent e) { + DataTipManager.get().handleEventFromDataTipComponent(e); + } + + protected void processMouseMotionEvent(MouseEvent e) { + DataTipManager.get().handleEventFromDataTipComponent(e); + } + + protected void processMouseWheelEvent(MouseWheelEvent e) { + DataTipManager.get().handleEventFromDataTipComponent(e); + } + + public void paintComponent(Graphics g) { + Component component = cell.getRendererComponent(); + + // Leave the component's opacity settings as is, just paint the background myself. + // This seems to be the only viable solution: DefaultTableCellRenderer overrides isOpaque() and returns + // true only if renderer color does not equal parent color. The problem is that rendererPane.paintComponent() + // re-parents the renderer. + g.setColor(backgroundColor); + int width = getWidth(); + int height = getHeight(); + g.fillRect(0, 0, width, height); + + g.setColor(Color.black); + g.drawRect(0, 0, width - 1, height - 1); + + if (withoutBorderRectangle != null) { + Shape oldClip = g.getClip(); + g.setClip(withoutBorderRectangle); + g.setColor(backgroundColor); + g.fillRect(0, 0, width, height); + g.setClip(oldClip); + } + + g.setClip(1, 1, width - 2, height - 2); + rendererPane.paintComponent(g, component, this, 0, 0, width, height); + g.setClip(withoutBorderRectangle); + rendererPane.paintComponent(g, component, this, 0, 0, width, height); + } + + public void setHeavyWeight(boolean isHeavyWeight) { + this.isHeavyWeight = isHeavyWeight; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipComponent.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipListener.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipListener.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipListener.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import javax.swing.*; +import javax.swing.event.MouseInputAdapter; +import java.awt.*; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.MouseEvent; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +abstract class DataTipListener extends MouseInputAdapter implements ComponentListener { + private DataTipPopup dataTipPopup; + + // When running under JDK 1.5 (or higher) DataTipListener will check if the tip must be updated when the parent + // component changes size or moves. + // With JDK 1.4 or earlier this does not work, because no mouse event gets posted (even though the relative mouse + // position changes) - yet to be able to compile with 1.4 the necessary JDK 1.5 methods are called by reflection. + // On JDK 1.4 the popup is just always hidden qwhen the component changes (and reshown when the user first moves + // the mouse again). + private static final Class[] NO_PARAMETERS = new Class[0]; + private static final Object[] NO_ARGUMENTS = new Object[0]; + private static Class mouseInfoClass; + private static Method getPointerInfoMethod; + private static Class pointerInfoClass; + private static Method getLocationMethod; + + static { + try { + mouseInfoClass = Class.forName("java.awt.MouseInfo"); + getPointerInfoMethod = mouseInfoClass.getMethod("getPointerInfo", NO_PARAMETERS); + pointerInfoClass = Class.forName("java.awt.PointerInfo"); + getLocationMethod = pointerInfoClass.getMethod("getLocation", NO_PARAMETERS); + } + catch(NoSuchMethodException e) { + // fine probably running on pre-1.5-JDK + } + catch(ClassNotFoundException e) { + // fine probably running on pre-1.5-JDK + } + } + + DataTipListener() { + } + + /** + * @return the cell that is at position 'point' in the component or DataTipCell.NONE if there isn't a cell at that + * point. + */ + abstract DataTipCell getCell(JComponent component, Point point); + + /** + * If the user presses a mouse button on a popup, Swing's behaviour depends on the popup type: + * - lightweight popup: + * This case is handled here. Because the TipComponent.contains(int x, int y) is overriden to always return false + * Swing will dispath the event directly to the parent component. + * - heavyweight popup: + * Swing will dispatch the event to the popup's window, which is handled in DataTipPopup. + */ + public void mousePressed(MouseEvent e) { + //hideTip(); Can't: Double click would not work. Click count of the second click would be '1', because it would + // go to a different window (for heavyweight datatips). + } + + public void mouseEntered(MouseEvent event) { + checkShowOrHide(event); + } + + public void mouseExited(MouseEvent event) { + checkShowOrHide(event); + } + + public void mouseDragged(MouseEvent event) { + checkShowOrHide(event); + } + + public void mouseMoved(MouseEvent event) { + checkShowOrHide(event); + } + + private void checkShowOrHide(MouseEvent event) { + JComponent component = (JComponent) event.getSource(); + Point mousePosition = event.getPoint(); + checkShowOrHide(component, mousePosition); + } + + private void checkShowOrHide(JComponent component, Point mousePosition) { + Window windowAncestor = SwingUtilities.getWindowAncestor(component); + if (windowAncestor == null || !windowAncestor.isActive()) { + hideTip(); + return; + } + + DataTipCell dataTipCell = getCell(component, mousePosition); + Rectangle visRect = component.getVisibleRect(); + + if(!visRect.contains(mousePosition)) { + dataTipCell = DataTipCell.NONE; + } + + DataTipCell currentPopupCell = getCurrentPopupCell(); + if(dataTipCell.equals(currentPopupCell)) { + return; + } + + hideTip(); + if(!dataTipCell.isSet()) { + return; + } + + dataTipPopup = createPopup(component, mousePosition, dataTipCell); + } + + private DataTipCell getCurrentPopupCell() { + if(!isTipShown()) { + return DataTipCell.NONE; + } + return dataTipPopup.getCell(); + } + + private DataTipPopup createPopup(JComponent component, Point mousePosition, DataTipCell dataTipCell) { + Rectangle cellBounds = dataTipCell.getCellBounds(); + + Rectangle visRect = component.getVisibleRect(); + Rectangle visibleCellRectangle = cellBounds.intersection(visRect); + if (!visibleCellRectangle.contains(mousePosition)) { + return null; + } + + Component rendererComponent = dataTipCell.getRendererComponent(); + Dimension rendCompDim = rendererComponent.getMinimumSize(); + Rectangle rendCompBounds = new Rectangle(cellBounds.getLocation(), rendCompDim); + if(cellBounds.contains(rendCompBounds) && visRect.contains(rendCompBounds)) { + return null; + } + + Dimension preferredSize = rendererComponent.getPreferredSize(); + Point tipPosition = cellBounds.getLocation(); + int width = Math.max(cellBounds.width, preferredSize.width); + int height = Math.max(cellBounds.height, preferredSize.height); + Dimension tipDimension = new Dimension(width, height); + DataTipPopup dataTipPopup = new DataTipPopup(component, dataTipCell, tipPosition, tipDimension); + + return dataTipPopup; + } + + private boolean isTipShown() { + return dataTipPopup != null && dataTipPopup.isTipShown(); + } + + private void hideTip() { + if (dataTipPopup != null) { + dataTipPopup.hideTip(); + dataTipPopup = null; + } + } + + public void componentResized(ComponentEvent e) { + checkShowOrHide(e); + } + + public void componentMoved(ComponentEvent e) { + checkShowOrHide(e); + } + + public void componentShown(ComponentEvent e) { + checkShowOrHide(e); + } + + public void componentHidden(ComponentEvent e) { + hideTip(); + } + + private void checkShowOrHide(ComponentEvent e) { + JComponent component = (JComponent) e.getSource(); + Point mousePosition = getCurrentMousePosition(); + if(mousePosition == null) { + hideTip(); + } + else { + SwingUtilities.convertPointFromScreen(mousePosition, component); + checkShowOrHide(component, mousePosition); + } + } + + private static Point getCurrentMousePosition() { + if(mouseInfoClass == null) { + return null; + } + try { + Object pointerInfo = getPointerInfoMethod.invoke(null, NO_ARGUMENTS); + Point mousePosition = (Point) getLocationMethod.invoke(pointerInfo, NO_ARGUMENTS); + return mousePosition; + } + catch(IllegalAccessException e) { + // strange, but nothing I can do here + } + catch(InvocationTargetException e) { + // strange, but nothing I can do here + } + + return null; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipManager.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipManager.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipManager.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.AWTEventListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; +import java.security.AccessControlException; + +/** + * <code>DataTipManager</code> provides data tips for tree, table and list components. Whenever the mouse cursor is + * over a cell whose content is partially hidden a popup with the complete cell content is shown. + * The cell content can be hidden because it is clipped at either the parent component bounds (e.g. scrollpane) or at + * the cell bounds (e.g. table row height is too small). + */ +public class DataTipManager { + private static DataTipManager instance; + + private ListDataTipListener listMouseListener = new ListDataTipListener(); + private TableDataTipListener tableMouseListener = new TableDataTipListener(); + private TreeDataTipListener treeMouseListener = new TreeDataTipListener(); + private Component parentComponent; + private Window tipComponentWindow; + private MouseEvent lastMouseEvent; + private static boolean allowUntrustedUsage; + + private DataTipManager() { + try { + long eventMask = AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK; + Toolkit.getDefaultToolkit().addAWTEventListener(new MouseEventModifier(), eventMask); + } + catch(AccessControlException e) { + if(!allowUntrustedUsage) { + throw new RuntimeException("DataTipManager needs to run in a trusted application", e); + } + } + } + + static void enableUntrustedUsage(boolean enable) { + allowUntrustedUsage = enable; + } + + /** + * @return the single, shared instance of the DataTipmanager + */ + public static synchronized DataTipManager get() { + if(instance == null) { + instance = new DataTipManager(); + } + return instance; + } + + /** + * Enable data tips for a list component. + * @param list the list which should be enhanced with data tips. + */ + public synchronized void register(JList list) { + list.addMouseListener(listMouseListener); + list.addMouseMotionListener(listMouseListener); + list.addComponentListener(listMouseListener); + } + + /** + * Enable data tips for a tree component. + * @param tree the tree which should be enhanced with data tips. + */ + public synchronized void register(JTree tree) { + tree.addMouseListener(treeMouseListener); + tree.addMouseMotionListener(treeMouseListener); + tree.addComponentListener(treeMouseListener); + } + + /** + * Enable data tips for a list component. + * @param table the table which should be enhanced with data tips. + */ + public synchronized void register(JTable table) { + table.addMouseListener(tableMouseListener); + table.addMouseMotionListener(tableMouseListener); + table.addComponentListener(tableMouseListener); + } + + void setTipWindow(Component parentComponent, Window dataTipComponent) { + this.parentComponent = parentComponent; + tipComponentWindow = dataTipComponent; + } + + public boolean handleEventFromParentComponent(MouseEvent mouseEvent) { + // filter out events that come from client explicitly calling this method, but we have already handled in awt event listener + if(mouseEvent == lastMouseEvent) { + return false; + } + Object source = mouseEvent.getSource(); + if(source != parentComponent) { + return false; + } + int id = mouseEvent.getID(); + int x = mouseEvent.getX(); + int y = mouseEvent.getY(); + long when = mouseEvent.getWhen(); + int modifiers = mouseEvent.getModifiers(); + int clickCount = mouseEvent.getClickCount(); + boolean isPopupTrigger = mouseEvent.isPopupTrigger(); + if(id == MouseEvent.MOUSE_EXITED) { + Point point = SwingUtilities.convertPoint(parentComponent, x, y, tipComponentWindow); + if(tipComponentWindow.contains(point)) { + MouseEvent newEvent = new MouseEvent(parentComponent, MouseEvent.MOUSE_MOVED, when, modifiers, + x, y, clickCount, isPopupTrigger); + parentComponent.dispatchEvent(newEvent); + // If the datatip has been hidden as a result, then process the exit event, too, so that + // e.g. tooltips will hide. + boolean stillVisible = parentComponent != null; + return stillVisible; + } + } + return false; + } + + public void handleEventFromDataTipComponent(MouseEvent mouseEvent) { + mouseEvent.consume(); + int id = mouseEvent.getID(); + if(id != MouseEvent.MOUSE_ENTERED) { + int x = mouseEvent.getX(); + int y = mouseEvent.getY(); + Point point = SwingUtilities.convertPoint(mouseEvent.getComponent(), x, y, parentComponent); + + if(id == MouseEvent.MOUSE_EXITED && parentComponent.contains(point)) { + return; + } + long when = mouseEvent.getWhen(); + int modifiers = mouseEvent.getModifiers(); + int clickCount = mouseEvent.getClickCount(); + boolean isPopupTrigger = mouseEvent.isPopupTrigger(); + MouseEvent newEvent; + if(id == MouseEvent.MOUSE_WHEEL) { + MouseWheelEvent mouseWheelEvent = (MouseWheelEvent) mouseEvent; + int scrollType = mouseWheelEvent.getScrollType(); + int scrollAmount = mouseWheelEvent.getScrollAmount(); + int wheelRotation = mouseWheelEvent.getWheelRotation(); + newEvent = new MouseWheelEvent(parentComponent, id, when, modifiers, point.x, point.y, + clickCount, isPopupTrigger, scrollType, scrollAmount, + wheelRotation); + } + else { + newEvent = new MouseEvent(parentComponent, id, when, modifiers, point.x, point.y, + clickCount, isPopupTrigger); + } + Component parentComponentBackup = parentComponent; + parentComponent.dispatchEvent(newEvent); + if(parentComponent == null && id != MouseEvent.MOUSE_EXITED) { + MouseEvent exitEvent = new MouseEvent(parentComponentBackup, MouseEvent.MOUSE_EXITED, when, + modifiers, point.x, point.y, clickCount, isPopupTrigger); + parentComponentBackup.dispatchEvent(exitEvent); + } + if(tipComponentWindow != null && id != MouseEvent.MOUSE_MOVED) { + // mouse click might have changed appearance (e.g. selection color) + tipComponentWindow.repaint(); + } + } + } + + private class MouseEventModifier implements AWTEventListener { + private MouseEventModifier() { + } + + public void eventDispatched(AWTEvent event) { + if(tipComponentWindow == null) { + return; + } + Object source = event.getSource(); + + if(source == parentComponent) { + MouseEvent mouseEvent = (MouseEvent) event; + boolean filter = handleEventFromParentComponent(mouseEvent); + if(filter) { + mouseEvent.consume(); + } + else { + lastMouseEvent = mouseEvent; + } + } + } + } +} + Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipManager.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipPopup.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipPopup.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipPopup.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import javax.swing.*; +import java.awt.*; + +class DataTipPopup { + private Popup popup; + private DataTipCell cell; + + DataTipPopup(JComponent parent, DataTipCell cell, Point tipPosition, Dimension tipDimension) { + this.cell = cell; + Rectangle parentVisibleRect = parent.getVisibleRect(); + Rectangle withoutBorderRectangle = parentVisibleRect.intersection(new Rectangle(tipPosition, tipDimension)); + withoutBorderRectangle.translate(-tipPosition.x, -tipPosition.y); + + DataTipComponent dataTipComponent = new DataTipComponent(cell, withoutBorderRectangle, parent.getBackground()); + + Dimension tipDimensionClipped = new Dimension(tipDimension.width, tipDimension.height); + Window windowAncestor = SwingUtilities.getWindowAncestor(parent); + GraphicsConfiguration gc = windowAncestor.getGraphicsConfiguration(); + Rectangle screenBounds = gc.getBounds(); + Point tipScreenPosition = new Point(tipPosition.x, tipPosition.y); + SwingUtilities.convertPointToScreen(tipScreenPosition, parent); + Point tipPositionClipped = new Point(); + tipPositionClipped.x = Math.max(tipScreenPosition.x, screenBounds.x); + tipPositionClipped.y = Math.max(tipScreenPosition.y, screenBounds.y); + tipDimensionClipped.width = Math.min(screenBounds.x + screenBounds.width - tipPositionClipped.x, tipDimensionClipped.width); + tipDimensionClipped.height = Math.min(screenBounds.y + screenBounds.height - tipPositionClipped.y, tipDimensionClipped.height); + SwingUtilities.convertPointFromScreen(tipPositionClipped, parent); + dataTipComponent.setPreferredSize(tipDimensionClipped); + SwingUtilities.convertPointToScreen(tipPosition, parent); + + PopupFactory popupFactory = PopupFactory.getSharedInstance(); + popup = popupFactory.getPopup(parent, dataTipComponent, tipPosition.x, tipPosition.y); + popup.show(); + Window componentWindow = SwingUtilities.windowForComponent(parent); + Window tipWindow = SwingUtilities.windowForComponent(dataTipComponent); + //noinspection ObjectEquality + boolean isHeavyWeight = tipWindow != null && tipWindow != componentWindow; + dataTipComponent.setHeavyWeight(isHeavyWeight); + if (isHeavyWeight) { +// ToolTipManager.sharedInstance().registerComponent(dataTipComponent); + DataTipManager.get().setTipWindow(parent, tipWindow); + } + } + + DataTipCell getCell() { + return cell; + } + + void hideTip() { + if (popup != null) { + popup.hide(); + popup = null; + + DataTipManager.get().setTipWindow(null, null); + } + } + + public boolean isTipShown() { + return popup != null; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/DataTipPopup.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipCell.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipCell.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipCell.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; + +import javax.swing.*; +import java.awt.*; + +class ListDataTipCell implements DataTipCell { + private final JList list; + private final int rowIndex; + + ListDataTipCell(JList list, int rowIndex) { + this.list = list; + this.rowIndex = rowIndex; + } + + public boolean isSet() { + return rowIndex >= 0; + } + + public Rectangle getCellBounds() { + Rectangle cellRect = list.getCellBounds(rowIndex, rowIndex); + return cellRect; + } + + public Component getRendererComponent() { + Object item = list.getModel().getElementAt(rowIndex); + boolean isSelected = list.isSelectedIndex(rowIndex); + boolean isFocussed = list.hasFocus() && rowIndex == list.getLeadSelectionIndex(); + ListCellRenderer renderer = list.getCellRenderer(); + Component component = renderer.getListCellRendererComponent(list, item, rowIndex, isSelected, isFocussed); + return component; + } + + public boolean equals(Object o) { + if(this == o) { + return true; + } + if(o == null || getClass() != o.getClass()) { + return false; + } + + ListDataTipCell listDataTipCell = (ListDataTipCell) o; + + if(rowIndex != listDataTipCell.rowIndex) { + return false; + } + + return true; + } + + public int hashCode() { + return rowIndex; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipCell.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipListener.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipListener.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipListener.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; +import com.xduke.xswing.DataTipListener; +import com.xduke.xswing.ListDataTipCell; + +import javax.swing.*; +import java.awt.*; + +class ListDataTipListener extends DataTipListener { + ListDataTipListener() { + } + + DataTipCell getCell(JComponent component, Point point) { + JList list = (JList) component; + int index = list.locationToIndex(point); + if (index < 0) { + return DataTipCell.NONE; + } + return new ListDataTipCell(list, index); + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/ListDataTipListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipCell.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipCell.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipCell.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; + +import javax.swing.*; +import javax.swing.table.TableCellRenderer; +import java.awt.*; + +class TableDataTipCell implements DataTipCell { + private final JTable table; + private final int rowIndex; + private final int columnIndex; + + TableDataTipCell(JTable table, int rowIndex, int columnIndex) { + this.table = table; + this.rowIndex = rowIndex; + this.columnIndex = columnIndex; + } + + public boolean isSet() { + return rowIndex >= 0 && columnIndex >= 0; + } + + public Rectangle getCellBounds() { + Rectangle cellRect = table.getCellRect(rowIndex, columnIndex, false); + return cellRect; + } + + public Component getRendererComponent() { + TableCellRenderer cellRenderer = table.getCellRenderer(rowIndex, columnIndex); + Component component = table.prepareRenderer(cellRenderer, rowIndex, columnIndex); + return component; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TableDataTipCell cellPosition = (TableDataTipCell) o; + + if (columnIndex != cellPosition.columnIndex) { + return false; + } + if (rowIndex != cellPosition.rowIndex) { + return false; + } + + return true; + } + + public int hashCode() { + int result; + result = rowIndex; + result = 29 * result + columnIndex; + return result; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipCell.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipListener.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipListener.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipListener.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; +import com.xduke.xswing.DataTipListener; +import com.xduke.xswing.TableDataTipCell; + +import javax.swing.*; +import java.awt.*; + +class TableDataTipListener extends DataTipListener { + TableDataTipListener() { + } + + DataTipCell getCell(JComponent component, Point point) { + JTable table = (JTable) component; + int rowIndex = table.rowAtPoint(point); + int columnIndex = table.columnAtPoint(point); + if (rowIndex < 0 || columnIndex < 0) { + return DataTipCell.NONE; + } + TableDataTipCell cellPosition = new TableDataTipCell(table, rowIndex, columnIndex); + return cellPosition; + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TableDataTipListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipCell.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipCell.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipCell.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; + +import javax.swing.*; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeCellRenderer; +import java.awt.*; + +class TreeDataTipCell implements DataTipCell { + private final JTree tree; + private final int rowIndex; + + public TreeDataTipCell(JTree tree, int rowIndex) { + this.tree = tree; + this.rowIndex = rowIndex; + } + + public boolean isSet() { + return rowIndex >= 0; + } + + public Rectangle getCellBounds() { + TreePath treePath = tree.getPathForRow(rowIndex); + Rectangle cellRect = tree.getPathBounds(treePath); + return cellRect; + } + + public Component getRendererComponent() { + TreeModel treeModel = tree.getModel(); + TreePath treePath = tree.getPathForRow(rowIndex); + TreeCellRenderer renderer = tree.getCellRenderer(); + boolean isSelected = tree.isPathSelected(treePath); + boolean isExpanded = tree.isExpanded(treePath); + boolean hasFocus = tree.hasFocus() && rowIndex == tree.getLeadSelectionRow(); + Object item = treePath.getLastPathComponent(); + boolean isLeaf = treeModel.isLeaf(item); + Component component = renderer.getTreeCellRendererComponent(tree, item, isSelected, isExpanded, isLeaf, rowIndex, hasFocus); + component.setFont(tree.getFont()); + return component; + } + + public boolean equals(Object o) { + if(this == o) { + return true; + } + if(o == null || getClass() != o.getClass()) { + return false; + } + + TreeDataTipCell treeDataTipCell = (TreeDataTipCell) o; + + if(rowIndex != treeDataTipCell.rowIndex) { + return false; + } + + return true; + } + + public int hashCode() { + return rowIndex; + } +} + Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipCell.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipListener.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipListener.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipListener.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002 - 2005, Stephen Kelvin Friedrich. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this list + * of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, this + * list of conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors may be + * used to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.xduke.xswing; + +import com.xduke.xswing.DataTipCell; +import com.xduke.xswing.DataTipListener; +import com.xduke.xswing.TreeDataTipCell; + +import javax.swing.*; +import java.awt.*; + +class TreeDataTipListener extends DataTipListener { + TreeDataTipListener() { + } + + DataTipCell getCell(JComponent component, Point point) { + JTree tree = (JTree) component; + int rowIndex = tree.getRowForLocation(point.x, point.y); + if (rowIndex < 0) { + return DataTipCell.NONE; + } + return new TreeDataTipCell(tree, rowIndex); + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/com/xduke/xswing/TreeDataTipListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTableModel.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTableModel.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTableModel.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,128 @@ +/* * + * Copyright (C) 2010 ceric35 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ +package org.nuiton.test; + +import java.io.File; + +import javax.swing.event.TreeModelListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.views.AbstractView; + +/** + * BasicTableModel + * + * TODO ADD COMMENT HERE ! + * + * @author ceric35 + * Date : 4 mars 2010 + */ +public class BasicTableModel extends AbstractTableModel { + + /** Logger */ + private static Logger logger = LoggerFactory.getLogger(BasicTableModel.class); + + protected File root; + + protected File[] children; + + public BasicTableModel(File rootFile) { + this.root = rootFile; + children = root.listFiles(); + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) + */ + public Object getChild(Object parent, int index) { + + File parentFile = (File)parent; + File[] children = parentFile.listFiles(); + return children[index]; + } + + /* + * @see javax.swing.table.TableModel#getRowCount() + */ + @Override + public int getRowCount() { + return children.length; + } + + /* + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + return 2; + } + + + /* + * @see javax.swing.table.AbstractTableModel#getColumnName(int) + */ + @Override + public String getColumnName(int column) { + String result = "n/a"; + + switch (column) { + case 0: result = "File"; break; + case 1: result = "Size"; break; + } + + return result; + } + + /* + * @see javax.swing.table.AbstractTableModel#getColumnClass(int) + */ + @Override + public Class<?> getColumnClass(int columnIndex) { + Class<?> result = null; + + switch (columnIndex) { + case 0: result = String.class; break; + case 1: result = Long.class; break; + } + + return result; + } + + /* + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + + Object result = null; + File f = children[rowIndex]; + switch (columnIndex) { + case 0: result = f.getAbsolutePath(); break; + case 1: result = f.length(); break; + } + + return result; + } + + + +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTreeModel.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTreeModel.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTreeModel.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,119 @@ +/* * + * Copyright (C) 2010 ceric35 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ +package org.nuiton.test; + +import java.io.File; + +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreePath; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * BasicTreeModel + * + * TODO ADD COMMENT HERE ! + * + * @author ceric35 + * Date : 4 mars 2010 + */ +public class BasicTreeModel implements TreeModel { + + /** Logger */ + private static Logger logger = LoggerFactory.getLogger(BasicTreeModel.class); + + protected File root; + + public BasicTreeModel(File rootFile) { + this.root = rootFile; + } + + /* @see javax.swing.tree.TreeModel#getRoot() + */ + @Override + public Object getRoot() { + return root; + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) + */ + @Override + public Object getChild(Object parent, int index) { + + File parentFile = (File)parent; + File[] children = parentFile.listFiles(); + return children[index]; + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) + */ + @Override + public int getChildCount(Object parent) { + File parentFile = (File)parent; + File[] children = parentFile.listFiles(); + return children == null ? 0 : children.length; + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object) + */ + @Override + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#valueForPathChanged(javax.swing.tree.TreePath, java.lang.Object) + */ + @Override + public void valueForPathChanged(TreePath path, Object newValue) { + + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object, java.lang.Object) + */ + @Override + public int getIndexOfChild(Object parent, Object child) { + return 0; + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener) + */ + @Override + public void addTreeModelListener(TreeModelListener l) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener) + */ + @Override + public void removeTreeModelListener(TreeModelListener l) { + // TODO Auto-generated method stub + + } + + +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/BasicTreeModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/CustomTreeFilter.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/CustomTreeFilter.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/CustomTreeFilter.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,36 @@ +/* * + * Copyright (C) 2010 ceric35 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ +package org.nuiton.test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * CustomTreeFilter + * + * TODO ADD COMMENT HERE ! + * + * @author ceric35 + * Date : 4 mars 2010 + */ +public class CustomTreeFilter { + + /** Logger */ + private static Logger logger = LoggerFactory.getLogger(Main.class); + +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/CustomTreeFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/Main.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/Main.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/Main.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,200 @@ +/* * + * Copyright (C) 2010 ceric35 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ +package org.nuiton.test; + +import java.awt.Color; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.io.IOException; + +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JToolTip; +import javax.swing.JTree; + +import net.java.balloontip.BalloonTip; +import net.java.balloontip.styles.RoundedBalloonStyle; +import net.java.balloontip.utils.ToolTipUtils; + +import org.jdesktop.application.SessionStorage; +import org.nuiton.test.saf.SafApplicationContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.xduke.xswing.DataTipManager; + +/** + * Main + * + * @author ceric35 + * Date : 4 mars 2010 + */ +public class Main extends JFrame { + + /** Logger */ + private static Logger logger = LoggerFactory.getLogger(Main.class); + + public Main() throws IOException { + + // label filter + JPanel leftPanel = new JPanel(new GridBagLayout()); + JLabel filterLabel = new JLabel("Filtre : "); + leftPanel.add(filterLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(2, 2, 2, 2), 0, 0)); + + // field filter + JTextField filterField = new JTextField(); + leftPanel.add(filterField, new GridBagConstraints(1, 0, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, + new Insets(2, 2, 2, 2), 0, 0)); + + // tree + BasicTreeModel treeModel = new BasicTreeModel(new File(".") + .getCanonicalFile()); + JTree tree = new JTree(treeModel); + tree.setName("tree"); + leftPanel.add(new JScrollPane(tree), new GridBagConstraints(0, 1, 2, 1, + 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(2, 2, 2, 2), 0, 0)); + DataTipManager.get().register(tree); + + JPanel rigthPanel = new JPanel(new GridBagLayout()); + // label tootip + JLabel testToottip = new JLabel("Over me !!!!!") { + @Override + public JToolTip createToolTip() { + JToolTip tt = new JToolTip(); + /*BalloonTip bt = new BalloonTip(this, this.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), false); + bt.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + + BalloonTip source = (BalloonTip)e.getSource(); + source.closeBalloon(); + + BalloonTip bt = new BalloonTip(source, source.getToolTipText(), new RoundedBalloonStyle(5,5,Color.WHITE, Color.BLACK), true); + bt.setVisible(true); + } + + }); + //ToolTipUtils.balloonToToolTip(bt, 500, 3000); + tt.setComponent(this);*/ + return tt; + } + }; + testToottip.setToolTipText("Alors ?"); + + BalloonTip bt = new BalloonTip(testToottip, testToottip + .getToolTipText(), new RoundedBalloonStyle(5, 5, Color.WHITE, + Color.BLACK), false); + bt.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + logger.debug("Called"); + BalloonTip source = (BalloonTip) e.getSource(); + source.setVisible(false); + source.setEnabled(false); + BalloonTip bt = new BalloonTip( + source.getAttachedComponent(), + source.getAttachedComponent().getToolTipText(), + new RoundedBalloonStyle(5, 5, Color.WHITE, Color.BLACK), + true); + bt.setVisible(true); + } + }); + ToolTipUtils.balloonToToolTip(bt, 500, 3000); + rigthPanel.add(testToottip, new GridBagConstraints(0, 0, 1, 1, 1, 0, + GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets( + 2, 2, 2, 2), 0, 0)); + + // table + BasicTableModel tableModel = new BasicTableModel(new File(".") + .getCanonicalFile()); + JTable table = new JTable(tableModel); + table.setName("table"); + rigthPanel.add(new JScrollPane(table), new GridBagConstraints(0, 1, 1, + 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + new Insets(2, 2, 2, 2), 0, 0)); + DataTipManager.get().register(table); + + // end UI + + JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rigthPanel); + pane.setName("mainViewPane"); + + add(pane); + } + + public static void main(String[] args) throws IOException { + final Main m = new Main(); + m.setName("mainFrame"); + + // centering + centerWindow(m); + + SafApplicationContext context = new SafApplicationContext(); + final SessionStorage sessionStorage = context.getSessionStorage(); + sessionStorage.restore(m, m.getName() + "-session.xml"); + + m.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + try { + sessionStorage.save(m, m.getName() + "-session.xml"); + System.exit(0); + } catch (IOException ex) { + logger.error("Can't save frame session", ex); + } + } + }); + m.setVisible(true); + } + + protected static void centerWindow(Window root) { + // If the window's bounds don't appear to have been set, do it + if (root instanceof Window) { + Window window = (Window) root; + if (!root.isValid() || (root.getWidth() == 0) + || (root.getHeight() == 0)) { + window.pack(); + } + if (!window.isLocationByPlatform() && (root.getX() == 0) + && (root.getY() == 0)) { + Component owner = window.getOwner(); + //if (owner == null) { + // owner = (window != mainFrame) ? mainFrame : null; + //} + window.setLocationRelativeTo(owner); // center the window + } + } + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/Main.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/TreeFilter.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/TreeFilter.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/TreeFilter.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,31 @@ +/* * + * Copyright (C) 2010 ceric35 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + **/ +package org.nuiton.test; + +/** + * TreeFilter + * + * TODO ADD COMMENT HERE ! + * + * @author ceric35 + * Date : 4 mars 2010 + */ +public interface TreeFilter { + + public boolean include(Object o); +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/TreeFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MainApplication.properties =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MainApplication.properties (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/resources/MainApplication.properties 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1 @@ +Application.id=testtesttest \ No newline at end of file Added: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/SafApplicationContext.java =================================================================== --- testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/SafApplicationContext.java (rev 0) +++ testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/SafApplicationContext.java 2010-03-04 16:06:40 UTC (rev 387) @@ -0,0 +1,39 @@ +/* *##% + * Copyright (C) 2010 Code Lutin, Chatellier Eric + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package org.nuiton.test.saf; + +import org.jdesktop.application.Application; +import org.jdesktop.application.ApplicationContext; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SafApplicationContext extends ApplicationContext { + + public SafApplicationContext() { + super(); + setApplicationClass(Application.class); + } +} Property changes on: testTreeTooltipSession/trunk/src/main/java/org/nuiton/test/saf/SafApplicationContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL
participants (1)
-
echatellier@users.nuiton.org