/******************************* 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.model; import java.awt.Component; import java.awt.FontMetrics; import java.awt.Graphics; //import adiag.util.Toolz; /** * Container / utils for some constants. * @author Andrei Loskutov */ public class Const { /** * *D:\>p4 info *User name: Andy_the_Great *Client name: andy *Client host: andy *Client root: h:\cvs_work *Current directory: d:\ *Client address: 127.0.0.1:1384 *Server address: andy:1666 *Server root: h:\p4server *Server date: 2002/05/15 19:30:15 Westeuropische Sommerzeit *Server version: P4D/NTX86/2001.1/27396 (2001/11/01) *Server license: none */ /** true, if JDK == 1.4.* */ private static Boolean is1_4vm; /** Full path to the P4 executable * =D:\\Program Files\\Perforce\\P4.EXE */ public static final String PROPERTY_P4_EXEC = "p4.executable"; /** P4PORT to connect to. * =public.perforce.com:1666 */ public static final String PROPERTY_P4_PORT = "p4.port"; /** P4USER to run as. * =david_markley */ public static final String PROPERTY_P4_USER = "p4.user"; /** P4CLIENT to use. * =dmarkley-test */ public static final String PROPERTY_P4_CLIENT = "p4.client"; /** P4PASSWD to use for the P4USER, if one has been set. * =mylittlesecret */ public static final String PROPERTY_P4_PASSWD = "p4.password"; /** flag to save our log to file */ public static final String PROPERTY_DEBUG = "p4.save_log"; /** flag to read our data from our log file */ public static final String PROPERTY_OFFLINE = "p4.read_log_offline"; /** flag to read our data from p4 and if we found more branches, fetch info for new branches too */ public static final String PROPERTY_DISCOVER_ALL = "p4.fetch_all_branches"; /** where to search for external diff tool */ public static final String PROPERTY_DIFF_FILE = "p4.diff_exe_path"; /** last build */ public static final String BUILD_DATE = "09.12.2002"; /** last revision */ public static final String BUILD_REVISION = "1.3.0.1 beta"; /** all known properties */ public static final String[] PROPERTIES = { PROPERTY_P4_EXEC, PROPERTY_P4_PORT, PROPERTY_P4_USER, PROPERTY_P4_CLIENT, PROPERTY_P4_PASSWD, PROPERTY_DEBUG, PROPERTY_OFFLINE, PROPERTY_DISCOVER_ALL, PROPERTY_DIFF_FILE }; /** Config file name (not the path!) */ public static final String INI_FILE = "tp4branchview.ini"; /** external diff file path */ public static final String DIFF_FILE = "examdiff.exe"; /** p4 executable file name */ public static final String P4_EXE_FILE = "p4.exe"; /** Default- horiz. space of VersionView's in layout */ public static final int H_SPACE_D = 70; /** Default- vertical space of VersionView's in layout */ public static final int V_SPACE_D = 20; /** Default- height of characters in Layout */ public static final float CHARACTER_V_SIZE_D = 14; /** Default- width of characters in layout */ public static final float CHARACTER_H_SIZE_D = 6.5f; /** current horiz. space of VersionView's in Layout */ public static int H_SPACE = H_SPACE_D; /** current vertical space of VersionView's in Layout */ public static int V_SPACE = V_SPACE_D; /** current height of characters in Layout */ public static float CHARACTER_V_SIZE = CHARACTER_V_SIZE_D; /** current width of characters in layout */ public static float CHARACTER_H_SIZE = CHARACTER_H_SIZE_D; /** vertical step by layout */ public static final int STEP_V = 3; /** horizontal step in layout */ public static final int STEP_H = 10; /** type of P4 Change-Log-entry */ public static final String TYPE_BRANCH = "branch"; /** type of P4 Change-Log-entry */ public static final String TYPE_COPY = "copy"; /** type of P4 Change-Log-entry */ public static final String TYPE_EDIT = "edit"; /** type of P4 Change-Log-entry */ public static final String TYPE_MERGE = "merge"; /** type of P4 Change-Log-entry */ public static final String TYPE_INTEGRATE = "integrate"; /** type of P4 Change-Log-entry */ public static final String TYPE_DELETE = "delete"; /** type of P4 Change-Log-entry */ public static final String TYPE_IGNORED = "ignored"; /** type of P4 Change-Log-entry */ public static final String TYPE_ADD = "add"; /** start line of P4 Log-entry */ public static final String LINE_BRANCH_FROM = "branch from"; /** start line of P4 Log-entry */ public static final String LINE_BRANCH_INTO = "branch into"; /** start line of P4 Log-entry */ public static final String LINE_COPY_FROM = "copy from"; /** start line of P4 Log-entry */ public static final String LINE_COPY_INTO = "copy into"; /** start line of P4 Log-entry */ public static final String LINE_EDIT_FROM = "edit from"; /** start line of P4 Log-entry */ public static final String LINE_EDIT_INTO = "edit into"; /** start line of P4 Log-entry */ public static final String LINE_MERGE_FROM = "merge from"; /** start line of P4 Log-entry */ public static final String LINE_MERGE_INTO = "merge into"; /** start line of P4 Log-entry */ public static final String LINE_IGNORED_FROM = "ignored"; /** start line of P4 Log-entry */ public static final String LINE_IGNORED_INTO = "ignored by"; /** start line of P4 Log-entry */ public static final String LINE_ADD_INTO = "add into"; /** number of known into/from types */ public static final int FROM_NUMBER = 5; /** order is important!!! * we use somtimes index !!! */ public static final String[] LINES = { LINE_BRANCH_FROM, LINE_COPY_FROM, LINE_EDIT_FROM, LINE_MERGE_FROM, LINE_IGNORED_FROM, // FROM_NUMBER = 5 // don't forget to set FROM_NUMBER !!! LINE_BRANCH_INTO, LINE_COPY_INTO, LINE_EDIT_INTO, LINE_MERGE_INTO, LINE_IGNORED_INTO, LINE_ADD_INTO }; /** * what type of log entry is it?? * @param line the Log-entry from Perforce * @return one of Const.LINE_ ... constants */ public static String getChangeType(String from_or_into_change_line) { if (from_or_into_change_line.startsWith(Const.LINE_BRANCH_FROM)) return Const.TYPE_BRANCH; else if (from_or_into_change_line.startsWith(Const.LINE_BRANCH_INTO)) return Const.TYPE_BRANCH; else if (from_or_into_change_line.startsWith(Const.LINE_COPY_FROM)) return Const.TYPE_COPY; else if (from_or_into_change_line.startsWith(Const.LINE_COPY_INTO)) return Const.TYPE_COPY; else if (from_or_into_change_line.startsWith(Const.LINE_EDIT_FROM)) return Const.TYPE_EDIT; else if (from_or_into_change_line.startsWith(Const.LINE_EDIT_INTO)) return Const.TYPE_EDIT; else if (from_or_into_change_line.startsWith(Const.LINE_MERGE_FROM)) return Const.TYPE_MERGE; else if (from_or_into_change_line.startsWith(Const.LINE_MERGE_INTO)) return Const.TYPE_MERGE; // we change from/into order by "ignored" because // LINE_IGNORED_INTO contains LINE_IGNORED_FROM and second will be // never returned ... else if (from_or_into_change_line.startsWith(Const.LINE_IGNORED_INTO)) return Const.TYPE_IGNORED; else if (from_or_into_change_line.startsWith(Const.LINE_IGNORED_FROM)) return Const.TYPE_IGNORED; else if (from_or_into_change_line.startsWith(Const.LINE_ADD_INTO)) return Const.TYPE_ADD; else return "unknown"; } /** * what type of log entry is it?? * @param line the Log-entry from Perforce * @return one of Const.LINE_ ... constants */ public static int getStartLineCode(String line) { if (line.startsWith(Const.LINE_BRANCH_FROM)) return indexOfString(Const.LINES, Const.LINE_BRANCH_FROM); else if (line.startsWith(Const.LINE_BRANCH_INTO)) return indexOfString(Const.LINES, Const.LINE_BRANCH_INTO); else if (line.startsWith(Const.LINE_COPY_FROM)) return indexOfString(Const.LINES, Const.LINE_COPY_FROM); else if (line.startsWith(Const.LINE_COPY_INTO)) return indexOfString(Const.LINES, Const.LINE_COPY_INTO); else if (line.startsWith(Const.LINE_EDIT_FROM)) return indexOfString(Const.LINES, Const.LINE_EDIT_FROM); else if (line.startsWith(Const.LINE_EDIT_INTO)) return indexOfString(Const.LINES, Const.LINE_EDIT_INTO); else if (line.startsWith(Const.LINE_MERGE_FROM)) return indexOfString(Const.LINES, Const.LINE_MERGE_FROM); else if (line.startsWith(Const.LINE_MERGE_INTO)) return indexOfString(Const.LINES, Const.LINE_MERGE_INTO); // we change from/into order by "ignored" because // LINE_IGNORED_INTO contains LINE_IGNORED_FROM and second will be // never returned ... else if (line.startsWith(Const.LINE_IGNORED_INTO)) return indexOfString(Const.LINES, Const.LINE_IGNORED_INTO); else if (line.startsWith(Const.LINE_IGNORED_FROM)) return indexOfString(Const.LINES, Const.LINE_IGNORED_FROM); else if (line.startsWith(Const.LINE_ADD_INTO)) return indexOfString(Const.LINES, Const.LINE_ADD_INTO); else return -1; } /** * how long is well known start of the P4 log line * @param idx one of Const.LINE_ ... constants * @return the length of well known start of the P4 log line * @see Const */ public static int getStartLineCodeLength(int idx) { int command_length = -1; if (idx >= 0 && idx < LINES.length) { return LINES[idx].length() + 1; // +1 wegen des Leerzeichens am Ende } return command_length; } /** * the height of '0' character in actual context * @param gr * @return int the height of '0' character in actual context */ public static float getFontHeight(Graphics gr){ if(gr == null){ return CHARACTER_V_SIZE; } else { FontMetrics fm = gr.getFontMetrics(); CHARACTER_V_SIZE = fm.getHeight(); if(!is_1_4_Vm()){ CHARACTER_V_SIZE -= 3; } return CHARACTER_V_SIZE; } } /** * the height of '0' character in actual context * @param gr * @return the height of '0' character in actual context */ public static float getFontHeight(Component c){ if(c == null){ return CHARACTER_V_SIZE; } else { return getFontHeight(c.getGraphics()); } } /** * the width of given number of '0' characters in actual component * @param c actual component * @param charNumber number of characters * @return int width of given number of '0' characters in actual component */ public static float getFontWidth(Component c, String s){ if(c == null){ return CHARACTER_H_SIZE * s.length(); } else { return getFontWidth(c.getGraphics(), s); } } /** * the width of given number of '0' characters in actual context * @param gr actual context * @param charNumber number of characters * @return int width of given number of '0' characters in actual context */ public static float getFontWidth(Graphics gr, String s){ if(gr == null){ return CHARACTER_H_SIZE * s.length(); } else { FontMetrics fm = gr.getFontMetrics(gr.getFont()); int width = fm.stringWidth(s); if(is_1_4_Vm()){ width += s.length()*0.75; } return width; } } /** See return description * @param strings array to search * @param string String to search * @return -1 if not found or one of arguments is null, * else index of given string in array */ public static int indexOfString(String[] strings, String string) { if (strings == null) { return -1; } return indexOfString(strings, string, 0, strings.length); } /** See return description * @param strings array to search * @param string String to search * @param from start index, inclusive * @param to stop index, exclusive * @return -1 if not found or one of arguments is null, * else index of given string in array */ public static int indexOfString(String[] strings, String string, int from, int to) { if (strings == null || string == null || from > strings.length || to < 0) return -1; to = to > strings.length ? strings.length : to; from = from < 0 ? 0 : from; for (int i = from; i < to; i++) if (string.equals(strings[i])) return i; return -1; } /** * See return description * @return true, wenn JRE Version >= 1.3 ist */ public static boolean is_1_4_Vm() { if(is1_4vm == null){ String os = System.getProperty("java.vm.version", "1.2"); is1_4vm = new Boolean(os.charAt(2) > '3'); } return is1_4vm.booleanValue(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 2735 | andrei_loskutov | sources are now included to binary distribution at http://andrei.gmxhome.de/perforce/index.html | ||
#3 | 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. |
||
#2 | 2552 | andrei_loskutov | 1.3.0.4 changes | ||
#1 | 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 |