/******************************* 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.Color; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import java.util.Collections; import adiag.model.Const; import adiag.model.Version; import adiag.model.VersionComparator; /** * The "table-cell"-layout, simply sort all versions with their change-number and path * from left to right and from top to bottom * @author Andrei Loskutov */ public class SimpleLayout extends Layout { /** color of branch names */ private static final Color COLOR_PATH = Color.red.darker(); /** known paths, values are strings */ private ArrayList paths = new ArrayList(); /** * CLayout default constructor. */ public SimpleLayout() { super(); } /** * @param versions all known versions * @param view current view * @see Layout */ public SimpleLayout(Version[] versions, View view) { super(versions, view); } /** * See return description * @return true, if found one or more VersionView's under given coordinates * @param x coordinate * @param y coordinate */ public boolean contains(int x, int y) { ArrayList al = getElements(); int size = al.size(); for (int i = 0; i < size; i++) { if (((VersionView) al.get(i)).contains(x, y)) { return true; } } return false; } /** * Does layout of view, like: * <pre> * Path1 Path2 Path3 Path4 * Version1 * Version2 * Version3 * Version4 * Version5 * Version6 * Version7 * Version8 * </pre> * @see Layout */ public void doLayout() { // al contains branches ArrayList al = new ArrayList(branchTable.values()); // update list of paths paths.clear(); paths.addAll(branchTable.keySet()); int cols = al.size(); if (cols == 0) { return; } VersionComparator comp = new VersionComparator(); Collections.sort(al, comp); float y = Const.CHARACTER_V_SIZE * 2; int count = 0; int[] xpos = new int[cols]; float height = Const.getFontHeight(view); xpos[0] = Const.H_SPACE; // set "x position" constants for each branch for (int i = 1; i < xpos.length; i++) { xpos[i] += xpos[i - 1] + Const.H_SPACE; } // version with smallest change number Version min = (Version) al.get(0); // last version, needed only for path abbreviation Version last = (Version) al.get(al.size() - 1); int last_path_length = last.getPath().length(); int curr_col = 0; int last_change = min != null ? min.getChange() : -1; int curr_change = -1; int last_v_number = min != null ? min.getVersNumber() : -1; int curr_v_number = -1; String last_branch = min != null ? min.getPath().trim() : ""; String curr_branch = ""; VersionView v; float max_x = 0; float max_y = 0; float curr_x, curr_y; while (min != null) { v = getView(min); curr_x = xpos[curr_col] + v.dx; curr_y = y + v.dy; v.dx = (v.dy = 0); v.setFrame(curr_x, curr_y, getNodeWidth(min, view.getGraphics()), height); if (curr_x > max_x) { max_x = curr_x; } if (curr_y > max_y) { max_y = curr_y; } //next row: // replace working version through the next in branch al.set(curr_col, min.getNext()); min = Toolz.getFirst(al); curr_change = min != null ? min.getChange() : -1; curr_v_number = min != null ? min.getVersNumber() : -1; curr_branch = min != null ? min.getPath().trim() : ""; // switch to next row only if different changes number // or differ version in *same* branch if (curr_change != last_change || (curr_v_number != last_v_number && curr_branch.equals(last_branch))) { if(min!= null && getView(min).isCollapsed()){ y += height; } else { y += Const.V_SPACE + height; } } else { //y += height / 2; } last_change = curr_change; last_v_number = curr_v_number; last_branch = curr_branch; curr_col = al.indexOf(min); count++; } setMin(new Point(0, 0)); setMax( new Point((int) (max_x + last_path_length * Const.CHARACTER_H_SIZE), (int) (max_y + height * 6))); System.out.println("total " + count + " revisions"); } /** * See return description * @return bounds of view */ public Rectangle getBounds() { int width = this.max.x; //- this.min.x int height = this.max.y; // - this.min.y width = width > 100 ? width : 100; height = height > 100 ? height : 100; return new Rectangle(0, 0, width, height); } /** * See return description * @param x coordinate * @param y coordinate * @return the HTML- representation of founded version or null */ public String getInfo(int x, int y) { VersionView v = null; ArrayList al = getElements(); int size = al.size(); for (int i = 0; i < size; i++) { if ((v = (VersionView) al.get(i)).contains(x, y)) { return v.getVersion().toHtmlString(); } } return null; } /** * See return description * @return Point with lower right corner of 2D-view */ public Point getMax() { return new Point(max); } /** * See return description * @return Point with upper left corner of 2D-view */ public Point getMin() { return new Point(min); } /** * 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 VersionView getVersionView(int x, int y) { VersionView v; ArrayList al = getElements(); int size = al.size(); for (int i = 0; i < size; i++) { if ((v = (VersionView) al.get(i)).contains(x, y)) { return v; } } return null; } /** * Paint VersionView objects on given context * @param g context for painting */ public void paint(Graphics2D g) { VersionView vv; Version v; Color old_c = g.getColor(); String last_path = ""; ArrayList al = getElements(); int size = al.size(); for (int i = 0; i < size; i++) { vv = (VersionView) al.get(i); v = vv.getVersion(); // drwa path only on first occurence if (v.getPrev() == null) { g.setColor(COLOR_PATH); if (i == 0) { // size is at least one last_path = paths.get(paths.size() - 1).toString(); if (v.getPath().equals(last_path)) { last_path = paths.get(0).toString(); } } g.drawString( v.getAbbreviatedPath(last_path), (float) vv.getX(), (int) (vv.getY() - vv.getHeight() / 4)); last_path = v.getPath(); } vv.repaint(g); } g.setColor(old_c); } /** * Method toggleCompact turn extra info on/off for better gui feeling * for more compact view, or to all possible information */ public void toggleCompact(){ ArrayList elements = getElements(); VersionView [] branch = (VersionView[])elements.toArray(new VersionView[elements.size()]); Version vers = null; Version next = null; String type = null; for (int i = 0; i < branch.length; i++) { vers = branch[i].getVersion(); type = vers.getChangeType(); if(type != null && type.indexOf(Const.TYPE_EDIT) >= 0){ next = vers.getNext(); if(next != null){ type = next.getChangeType(); if(type != null && type.indexOf(Const.TYPE_EDIT) >= 0){ if(vers.getNextBranch() == null ){ branch[i].setCollapsed(!branch[i].isCollapsed()); } } } } } } /** * 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 void toggleCompact(VersionView view){ setCompact(view, COMPACT_STATE_REVERT); } /** * 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 void setCompact(VersionView view, int state){ VersionView [] branch = Toolz.getAllFromPath(view); Version vers = null; Version next = null; String type = null; for (int i = 0; i < branch.length; i++) { vers = branch[i].getVersion(); type = vers.getChangeType(); if(type != null && type.indexOf(Const.TYPE_EDIT) >= 0){ next = vers.getNext(); if(next != null){ type = next.getChangeType(); if(type != null && type.indexOf(Const.TYPE_EDIT) >= 0){ if(vers.getNextBranch() == null ){ if(COMPACT_STATE_REVERT == state){ branch[i].setCollapsed(!branch[i].isCollapsed()); } else { branch[i].setCollapsed(state == COMPACT_STATE_ON); } } } } } } } }
# | 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 |