/******************************* Copyright notice ******************************* Copyright (C)2002 by Andrei Loskutov <loskutov@gmx.de>. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 adiag.view; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Hashtable; import javax.swing.JComponent; import adiag.model.Const; import adiag.model.Version; import adiag.model.VersionComparator; /** * Abstract layout * @author Andrei Loskutov */ public abstract class Layout { /** "columns" of layout, as branches * key is path, * value are ArrayLists with Versions, from same branch */ protected Hashtable branchTable = new Hashtable(5); /** * key is version, value is view */ protected Hashtable versionToViewMap = new Hashtable(103); /** all known VersionView's */ protected ArrayList elements = new ArrayList(29); /** Point with lower right corner of 2D-view */ protected Point max = new Point(); /** Point with upper left corner of 2D-view */ protected Point min = new Point(); /** compact state */ protected static final int COMPACT_STATE_ON = 1; /** "expanded" view state */ protected static final int COMPACT_STATE_OFF = -1; /** toggle to opposite state */ protected static final int COMPACT_STATE_REVERT = 0; /** we need view to determine width and height of characters in a current context */ protected JComponent view; /** * Layout default constructor. */ public Layout() { super(); } /** * @param versions all known versions * @param view current view */ public Layout(Version[] versions, View view) { super(); if(view.getPlatform() == View.PLATFORM_SWING){ this.view = (JComponent)view; } else { this.view = null; // throw NullPointer: we don't implement SWT now view.equals(null); } // distribute versions into arrays setVersions(versions); } /** * Set all known VersionView's * @param elements all known VersionView's */ protected void setElements(ArrayList elements) { this.elements = elements; int size = elements.size(); VersionView vv = null; versionToViewMap.clear(); for (int i = 0; i < size; i++) { vv = (VersionView)elements.get(i); versionToViewMap.put(vv.getVersion(), vv); } } /** * See return description * @return ArrayList all known VersionView's */ public ArrayList getElements() { return elements; } /** * See return description * @param version version as key to search for view * @return known VersionView for given Version */ public VersionView getView(Version version) { if(version == null){ return null; } return (VersionView)versionToViewMap.get(version); } /** * See return description * @return true, if found one or more VersionView's under given coordinates * @param x coordinate * @param y coordinate */ public abstract boolean contains(int x, int y); /** * Does layout of view */ public abstract void doLayout(); /** * See return description * @return bounds of view */ public abstract Rectangle getBounds(); /** * See return description * @return all text data from founded version, or 'null' if nothing found * @param x coordinate * @param y coordinate */ public abstract String getInfo(int x, int y); /** * See return description * @return Point with lower right corner of 2D-view */ public abstract Point getMax(); /** * See return description * @return Point with upper left corner of 2D-view */ public abstract Point getMin(); /** * See return description * @param x coordinate * @param y coordinate * @return if found one or more VersionView's under given coordinates, * return only first of them */ public abstract VersionView getVersionView(int x, int y); /** * Paint VersionView objects on given context * @param g context for painting */ public abstract void paint(Graphics2D g); /** * Reset all custom user layout changes */ public void resetUserMoves() { ArrayList al = getElements(); int size = al.size(); float height = Const.getFontHeight(view); VersionView v; for (int i = 0; i < size; i++) { v = (VersionView) al.get(i); v.dx = (v.dy = 0); v.setFrame(v.x, v.y, getNodeWidth(v.getVersion(), view.getGraphics()), height); } } /** * See return description * @param v version * @param gr current context * @return node width on given context in layout, if node is null, return * general "6-character" width on context */ public float getNodeWidth(Version v, Graphics gr) { if (v != null) { return VersionView.PADDING_X * 2 + Const.getFontWidth( gr, v.getVersionAndChangeText() ); } else { return Const.getFontWidth(gr, "444444"); } } /** * Set lower right corner of 2D-view * @param p Point lower right corner of 2D-view */ public void setMax(Point p) { if (p != null) { this.max = new Point(p); } else { this.max = new Point(); } } /** * Set upper left corner of 2D-view * @param p Point upper left corner of 2D-view */ public void setMin(Point p) { if (p != null) { this.min = new Point(p); } else { this.min = new Point(); } } /** * Replace versions on layout * @param versions array with versions, each of then is single representant of * different branches, also "root" - version */ public void setVersions(Version[] versions) { String path; branchTable = new Hashtable(5); ArrayList al = new ArrayList(); VersionComparator comp = new VersionComparator(); int b = 0; // distribute versions in branch arrays for (int i = 0; i < versions.length; i++) { path = versions[i].getPath(); if (branchTable.containsKey(path)) { // ooo ? b = comp.compare(versions[i], branchTable.get(path)); if (b < 0) { // new version is newer ;) branchTable.put(path, versions[i]); } } else { branchTable.put(path, versions[i]); } al.addAll(createAllFromPathAsList(versions[i])); } setElements(al); // for better look toggleCompact(); } /** * See return description * @param vv VersionView any one version from branch * @return a list with all known VersionView objects from same branch or empty list */ public ArrayList createAllFromPathAsList(Version v) { v = Toolz.getFirst(v); ArrayList al = new ArrayList(); VersionView vv = this.getView(v); if(vv == null){ vv = new VersionView(v); } al.add(vv); while ((v = v.getNext()) != null) { VersionView vv2 = this.getView(v); if(vv2 == null){ vv2 = new VersionView(v); } al.add(vv2); } return al; } /** * Set/add versions for layout * @param versions array with versions, each of then is single representant of * different branches, also "root" - version */ public void addVersions(Version[] versions) { if(versions.length == 0){ return; } String path; Object old; VersionComparator comp = new VersionComparator(); // distribute versions in branch arrays for (int i = 0; i < versions.length; i++) { path = versions[i].getPath(); if (branchTable.containsKey(path)) { // ooo ? old = branchTable.get(path); int result = comp.compare(versions[i], old); // if we switch from offline to online and received in same depot same file // but our connector is wrong and old data is not available for new connector // also we re-set all versions data if(!versions[i].equals(old) && result == 0){ setVersions(versions); return; } if (result < 0) { // new version is newer ;) branchTable.put(path, versions[i]); } } else { branchTable.put(path, versions[i]); } } ArrayList branches = new ArrayList(branchTable.values()); ArrayList al = new ArrayList(); Version v; for (int i = 0; i < branches.size(); i++) { v = (Version)branches.get(i); // for better look al.addAll(createAllFromPathAsList(v)); //setCompact(getView(v), COMPACT_STATE_ON); } if(al.size()>0){ setElements(al); } for (int i = 0; i < branches.size(); i++) { v = (Version)branches.get(i); // for better look //al.addAll(createAllFromPathAsList(v)); setCompact(getView(v), COMPACT_STATE_ON); } } /** * Method toggleCompact turn extra info on/off for better gui feeling * for more compact view, or to all possible information */ public abstract void toggleCompact(); /** * Method toggleCompact turn extra info on/off only for given branch for better gui feeling * for more compact view, or to all possible information * @param view any one versionview from selected branch */ public abstract void toggleCompact(VersionView view); /** * Set extra info on/off only for given branch for better gui feeling * for more compact view, or to all possible information * @param view one versionview from selected branch * @param state one of COMPACT_STATE_ ... constants */ protected abstract void setCompact(VersionView view, int state); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#4 | 2554 | andrei_loskutov |
#25.12.2002 23:29 Revision 1.3.0.4 beta 1) Some small refactoring 2) First integration with P4eclipse: properties etc, thanks Boris Pr�ssmann 5) Better integration to Eclipse: use Eclipse internal compare tool for diff. 6) Fix some minor bugs. #14.12.2002 23:15 Revision 1.3.0.3 beta 1) Fix endless loop bug if p4 path was not set. 2) Fix never getting focus bug after error message shown 3) Fix painting bug on JDK 1.4.1 (must be verified!!!) 4) Some small refactoring 5) Fix error handling. 6) Fix some minor bugs. |
||
#3 | 2552 | andrei_loskutov | 1.3.0.4 changes | ||
#2 | 2460 | andrei_loskutov |
1) Change configuration: always reed properties 2) Change password store to hex format/password field 3) Create standalone/not standalone state for new branchview eclipse wrapper 4) Refactor all main classes to remove cyclic package dependency 5) Add workaround to fix new JDK 1.4.1 Swing bugs on JScrollPane/JViewPort 6) Add dispose methods to panel/connector 7) Minor internal GUI fixes/refactorings |
||
#1 | 2222 | andrei_loskutov |
#13.10.2002 22:16 Revision 1.2.1 1) Documentation task is finished... Yes!!! 2) New feature: copy P4 depot path 3) Some small fixes to menu shortkeys belongs ctrl + c and ctrl + d 4) Clipboard fix because of JDK 1.2 - 1.3 bug 5) Smallest refactoring on some methods. 6) Html help updated |