001    /*
002     * Copyright (C) 2008-2010 by Holger Arndt
003     *
004     * This file is part of the Universal Java Matrix Package (UJMP).
005     * See the NOTICE file distributed with this work for additional
006     * information regarding copyright ownership and licensing.
007     *
008     * UJMP is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU Lesser General Public License as
010     * published by the Free Software Foundation; either version 2
011     * of the License, or (at your option) any later version.
012     *
013     * UJMP is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016     * GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public
019     * License along with UJMP; if not, write to the
020     * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
021     * Boston, MA  02110-1301  USA
022     */
023    
024    package org.ujmp.gui;
025    
026    import javax.swing.JFrame;
027    
028    import org.ujmp.core.Matrix;
029    import org.ujmp.core.interfaces.GUIObject;
030    import org.ujmp.gui.util.FrameManager;
031    import org.ujmp.gui.util.UIDefaults;
032    
033    public abstract class AbstractGUIObject implements GUIObject {
034            private static final long serialVersionUID = -2271465024665498798L;
035    
036            public static final int X = Matrix.X;
037    
038            public static final int Y = Matrix.Y;
039    
040            public static final int Z = Matrix.Z;
041    
042            public static final int ROW = Matrix.ROW;
043    
044            public static final int COLUMN = Matrix.COLUMN;
045    
046            public static final int ALL = Matrix.ALL;
047    
048            private int modCount = 0;
049    
050            static {
051                    UIDefaults.setDefaults();
052            }
053    
054            public AbstractGUIObject() {
055            }
056    
057            public AbstractGUIObject(String label) {
058                    this();
059                    setLabel(label);
060            }
061    
062            public AbstractGUIObject(String label, String description) {
063                    this(label);
064                    setDescription(description);
065            }
066    
067            
068            public abstract String toString();
069    
070            public void fireValueChanged() {
071                    modCount++;
072            }
073    
074            public final JFrame showGUI() {
075                    return FrameManager.showFrame(this);
076            }
077    
078            public String getToolTipText() {
079                    StringBuilder s = new StringBuilder();
080                    s.append("<html>");
081                    s.append("<table>");
082                    s.append("<tr>");
083                    s.append("<td colspan=2><h3>" + getClass().getSimpleName()
084                                    + "</h3></td>");
085                    s.append("</tr>");
086                    s.append("<tr>");
087                    s.append("<td><b>Label:</b></td>");
088                    s.append("<td>" + getLabel() + "</td>");
089                    s.append("</tr>");
090                    s.append("<td><b>Description:</b></td>");
091                    s.append("<td>" + getDescription() + "</td>");
092                    s.append("</tr>");
093                    s.append("</table>");
094                    s.append("</html>");
095                    return s.toString();
096            }
097    
098            public int getModCount() {
099                    return modCount;
100            }
101    
102    }