/******************************* 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. ********************************************************************************/ /** * Created on 02.12.2002 * * To change this generated comment edit the template variable "filecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of file comments go to * Window>Preferences>Java>Code Generation. */ package adiag.gui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Event; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import java.util.HashMap; import javax.swing.Action; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import adiag.connection.Configuration; import adiag.connection.Connector; import adiag.model.Const; import adiag.model.Version; import adiag.view.Toolz; import adiag.view.VersionView; /** * @author Andy the Great * Menu creator helper * @author Andy the Great */ public class MenuCreator { JSlider zoom_slider; private ViewPanel panel; /** all known actions */ private HashMap actions; private Configuration app; private BranchView branchView; /** * Create the version menu * @return JPopupMenu the version menu */ protected JPopupMenu createEditPopup() { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = createCollapseOneMenu(); popup.add(mi); mi = createExploreOneMenu(); popup.add(mi); mi = createDiffMenu(); popup.add(mi); mi = createCopyMenu(); popup.add(mi); mi = createCopyDataMenu(); popup.add(mi); return popup; } /** * create the general view menu * @return JPopupMenu the general view menu */ protected JPopupMenu createViewPopup() { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = createSaveAsImageMenu(); popup.add(mi); mi = createSaveAsTextMenu(); popup.add(mi); mi = createCopyDataMenu(); popup.add(mi); mi = createSetPropsMenu(); popup.add(mi); popup.add(new JSeparator()); mi = createNewWindowMenu(); popup.add(mi); mi = createChangeFileMenu(); popup.add(mi); mi = createChangeLogfileMenu(); popup.add(mi); popup.add(new JSeparator()); mi = createRedoLayoutMenu(); popup.add(mi); mi = createCollapseAllMenu(); popup.add(mi); mi = createExploreAllMenu(); popup.add(mi); popup.add(new JSeparator()); JPanel pan = createZoomMenu(); popup.add(pan); pan = createXSpaceMenu(); popup.add(pan); pan = createYSpaceMenu(); popup.add(pan); popup.add(new JSeparator()); mi = createHelpMenu(); popup.add(mi); mi = createAboutMenu(); popup.add(mi); // because of slider SwingUtilities.updateComponentTreeUI(popup); return popup; } /** * See return description * @param html true for HTML format, false for plain text * @return String The "online" - help to application command line parameters */ public static String getParameterHelp(boolean html){ String lineBreak = "\n"; if(html){ lineBreak = "<p>"; } StringBuffer sb = new StringBuffer(500); sb.append("<b>Possible parameters</b> (order is important!):").append(lineBreak); sb.append("1) P4 user name").append(lineBreak); sb.append("2) P4 client name").append(lineBreak); sb.append("3) P4 server port like 'server_name.domain_name:port'").append(lineBreak); sb.append("4) P4 file path to depot file like '//a/b/c.txt'").append(lineBreak); sb.append("5) Optional: P4 executable path like 'c:\\progra~2\\perforce'").append(lineBreak); sb.append("6) Optional: user password").append(lineBreak); sb.append("7) Optional: '-props', to use property file and not parameter").append(lineBreak); sb.append("8) Optional: '-stat', to write log with data to file tp4branchview.log in user directory").append(lineBreak); sb.append("9) Optional: '-offline', to read input data from older BranchView logfile").append(lineBreak); sb.append("10) Optional: '-all', to fetch all known 'branches' from p4").append(lineBreak); sb.append("If '-props' flag is set, awaiting only P4 file path to depot file as first parameter").append(lineBreak); sb.append("like '//a/b/c.txt', all other parameters will be read from").append(lineBreak); sb.append("property file 'tp4branchview.ini', that must be in user home directory").append(lineBreak); sb.append("NT: %SystemRoot%\\profiles\\%UserName%,").append(lineBreak); sb.append("Windows 2000 %SystemDrive%\\\\my documents\\%UserName%").append(lineBreak); sb.append("<b>Simple property file</b> (will be used only if '-props' flag is passed):").append(lineBreak); sb.append("p4.user=Andy_the_Great").append(lineBreak); sb.append("p4.client=andy").append(lineBreak); sb.append("p4.port=1666").append(lineBreak); sb.append("p4.executable=p4.exe").append(lineBreak); sb.append("p4.password=xxxxxx").append(lineBreak); sb.append("p4.save_log=true").append(lineBreak); sb.append("p4.read_log_offline=false").append(lineBreak); sb.append("p4.fetch_all_branches=true").append(lineBreak); sb.append("p4.diff_exe_path=examdiff.exe").append(lineBreak); return sb.toString(); } /** * See return description * @param html true for HTML format, false for plain text * @return String The "online" - help to application (GUI) usage */ public static String getGuiHelp(boolean html){ String lineBreak = "\n"; if(html){ lineBreak = "<p>"; } StringBuffer sb = new StringBuffer(500); sb.append("<b>Keyboard usage:</b>").append(lineBreak); sb.append("CTRL + E collapse/expand either selected or all branches").append(lineBreak); sb.append("CTRL + C copy P4 depot path of selected revision to clipboard").append(lineBreak); sb.append("CTRL + D copy P4 data of the selected revision to clipboard").append(lineBreak); sb.append("CTRL + D copy P4 data over all known revisions to clipboard, if nothing selected").append(lineBreak); sb.append("CTRL + L open dialog to load data for view from log file").append(lineBreak); sb.append("CTRL + N open new window with same content").append(lineBreak); sb.append("CTRL + P open properties window").append(lineBreak); sb.append("CTRL + R redo view layout").append(lineBreak); sb.append("CTRL + S open dialog to save view as GIF-image(s) with one HTML overview file").append(lineBreak); sb.append("CTRL + T open dialog to save all view data as text").append(lineBreak); sb.append("CTRL + V change view to path from clipboard, if clipboard contains valid P4 depot path").append(lineBreak); sb.append("CTRL + '+' increase zoom (work only for current view)").append(lineBreak); sb.append("CTRL + '-' decrease zoom (work only for current view)").append(lineBreak); sb.append("'Pos 1' jump up").append(lineBreak); sb.append("'End' jump down").append(lineBreak); sb.append("F1 show online help").append(lineBreak); sb.append("<b>Mouse usage:</b>").append(lineBreak); sb.append("2x left click over revision fetch more data (if available) from Perforce.").append(lineBreak); sb.append("1x left click select first revision for a diff-tool,").append(lineBreak); sb.append("(deleted revisions cannot be compare!)").append(lineBreak); sb.append("everyone other clicked revision will be a second revision for a diff-tool.").append(lineBreak); sb.append("1x click over empty background skip current selection.").append(lineBreak); sb.append("1x left click <b>and</b> drag over revision move this revision,").append(lineBreak); sb.append("1x left click <b>and</b> drag over background scroll the view").append(lineBreak); sb.append("1x left click <b>+ CTRL + SHIFT hold</b> and drag over a revision move entire view.").append(lineBreak); sb.append("1x right click, (or 1x left click + CTRL hold) and drag over a revision move entire branch.").append(lineBreak); sb.append("1x right click over background open a general menu.").append(lineBreak); sb.append("1x right click over a revision open a special revision menu.").append(lineBreak); return sb.toString(); } /** * See return description * @return JMenuItem the help - menu entry */ private JMenuItem createHelpMenu() { StringBuffer sb = new StringBuffer("<html><body bgcolor='#F8FCE0'>"); sb.append("<table width=100% border=0 cellspacing=0 cellpadding=3>"); sb.append("<font size=2 face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>"); sb.append(getGuiHelp(true)); sb.append("</td></tr>"); sb.append("</font><font size=2 face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>"); sb.append(getParameterHelp(true)); sb.append("</td></tr></font>"); sb.append("</table></body></html>"); final JEditorPane lab = new JEditorPane("text/html", sb.toString()); lab.setPreferredSize(new Dimension(600, 400)); lab.setEditable(false); final JScrollPane scroll = new JScrollPane(lab); scroll.setPreferredSize(new Dimension(600, 400)); String command = Commands.COMMAND_HELP; JMenuItem mi = new JMenuItem(command); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_F1; } /** f1 */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke("F1"); } public void actionPerformed(ActionEvent e) { JOptionPane pane = new JOptionPane( scroll, JOptionPane.INFORMATION_MESSAGE); JDialog dialog = pane.createDialog(app.getJComponent(), "Quick help for BranchView"); dialog.setModal(false); dialog.show(); /* this is modal... * JOptionPane.showMessageDialog( app, scroll, "Quick help for BranchView", JOptionPane.INFORMATION_MESSAGE, null); */ } }; //mi.setAction(a); mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); mi.setIcon(App.ICON); //mi.setMnemonic(a.getMnemonic()); mi.setAccelerator(a.getKeyStroke()); return mi; } /** * See return description * @return JMenuItem the aboout - menu entry */ private JMenuItem createAboutMenu() { String os = System.getProperty("os.name", "unknown OS"); String vm = System.getProperty("java.vm.version", "???"); String home = System.getProperty("user.home"); String temp = System.getProperty("java.io.tmpdir"); StringBuffer sb = new StringBuffer("<html><body bgcolor='#F8FCE0'>"); //#FBFDEC #F0F8BA sb.append("<table width=100% border=0 cellspacing=5 cellpadding=5>"); sb.append("<font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>Version:</td><td nowrap>").append(Const.BUILD_REVISION).append("</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#F0F8BA><td nowrap>Build:</td><td nowrap>").append(Const.BUILD_DATE).append( "</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>Client OS:</td><td nowrap>").append(os).append( "</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#F0F8BA><td nowrap>Java VM:</td><td nowrap>").append(vm).append( "</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>User home:</td><td nowrap>").append(home).append( "</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#F0F8BA><td nowrap>%TEMP% dir:</td><td nowrap>").append(temp).append( "</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#FBFDEC><td nowrap>Author:</td><td nowrap>Loskutov Andrei</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#F0F8BA><td nowrap>Contact:</td><td nowrap>loskutov@gmx.de</td></tr>"); sb.append("</font><font face=Arial,Helvetica>"); sb.append("<tr bgcolor=#F0F8BA><td></td><td nowrap>Bug comments are welcome!</td></tr>"); sb.append("</font>"); sb.append("</table>"); final JEditorPane lab = new JEditorPane("text/html", sb.toString()); lab.setPreferredSize(new Dimension(500, 260)); lab.setEditable(false); String command = Commands.COMMAND_ABOUT; JMenuItem mi = new JMenuItem(command); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_A; } /** ctrl + a */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog( app.getJComponent(), lab, "About BranchView", JOptionPane.INFORMATION_MESSAGE, null); } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); mi.setIcon(App.ICON); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "change file" - menu entry */ private JMenuItem createChangeFileMenu() { String command = Commands.COMMAND_CHANGE_FILE; JMenuItem mi = new JMenuItem(command); mi.setActionCommand(command); mi.setToolTipText("select local file or receive file path from clipboard"); SimpleAction a = new SimpleAction(command) { private String path; public int getMnemonic() { return KeyEvent.VK_V; } /** ctrl + V */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { path = null; // received directly from keyboard and not from Menu if (e.getID() == -1) { path = Toolz.getClipboardContent(); if (Toolz.isPath(path)) { System.out.println("received clipboard content:'" + path + "'"); // may be directory? if(path.endsWith("/")){ path += "..."; } // don't change if same if(!app.isOffline() && app.getPath()!= null && app.getPath().trim().equals(path.trim())){ System.out.println("same path received, won't change..."); return; } } else { System.out.println("received clipboard content:'" + path + "' is not a valid path!"); path = null; return; } } else { String[] exts = new String[] {}; String[] desc = new String[] {}; File[] ff = Toolz.getFilesFromChooser( ".", JFileChooser.OPEN_DIALOG, exts, desc, false, JFileChooser.FILES_AND_DIRECTORIES, app.getJComponent()); if (ff.length <= 0) { return; } File f = ff[0]; if (f == null) { return; } path = f.getAbsolutePath(); if (f.isDirectory()) { path += "..."; } } if (path != null) { branchView.changeFile(path); } } }; mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); //mi.setActionCommand(command); //mi.setMnemonic(a.getMnemonic()); mi.setAccelerator(a.getKeyStroke()); return mi; } /** * See return description * @return JMenuItem the "load view data from log file" - menu entry */ private JMenuItem createChangeLogfileMenu() { String command = Commands.COMMAND_CHANGE_LOGFILE; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("load view data 'offline' from logfile"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_L; } /** ctrl + L */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { String[] exts = new String[] { "txt", "log" }; String[] desc = new String[] { "textfiles", "logfiles" }; int mode = JFileChooser.OPEN_DIALOG; File[] ff = Toolz.getFilesFromChooser( System.getProperty("user.home"), mode, exts, desc, false, JFileChooser.FILES_ONLY, app.getJComponent()); if (ff.length <= 0) { return; } File f = ff[0]; if (f == null) { return; } else { if (!f.getName().endsWith(".log") && !f.getName().endsWith(".txt")) { f = new File(f.getParentFile(), f.getName() + ".log"); } } app.setOffline(true); Connector c = app.getConnector(); c.setLogFile(f); if (app.isOffline()) { try { app.setPath(f.getAbsolutePath()); branchView.getBranchLayout().setVersions(c.getData()); branchView.refreshLayout(true); } catch (Exception ee) { app.error("Cannot read offline data:\n" + ee.getMessage(), ee); } } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "diff" - menu entry */ private JMenuItem createDiffMenu() { String command = Commands.COMMAND_DIFF; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("please click another version to see difference"); SimpleAction a = new SimpleAction(command) { public void actionPerformed(ActionEvent e) { if (branchView.getClicked() != null) { VersionView diffView = branchView.getClicked(); diffView.setSelected(true); branchView.setDiffView(diffView); JOptionPane.showMessageDialog( app.getJComponent(), "Please click another version to see difference", "Information:", JOptionPane.INFORMATION_MESSAGE); branchView.setNeed_re_paint(true); panel.repaint(); } } }; mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "open new window" - menu entry */ private JMenuItem createNewWindowMenu() { String command = Commands.COMMAND_NEW_WINDOW; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("open new window with same view"); SimpleAction a = new SimpleAction(command) { /** ctrl + N */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { final String path = app.getPath(); try { app.getPropsSetter().storeProperties(app); } catch (IOException ex) { app.error("Cannot store properties:\n" + ex.getMessage(), ex); } Thread t = new Thread(new Runnable() { public void run() { App app2 = new App(); app2.initFrame(new String[] { path, "-props" }); } }); t.start(); } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "load P4 info for all branches" - menu entry */ private JMenuItem createExploreAllMenu() { String command = Commands.COMMAND_EXPLORE_ALL_BRANCHES; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("load P4 info for all branches (if available)"); SimpleAction a = new SimpleAction(command) { /** ctrl + I */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_I, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { branchView.exploreAllVersions(); } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "load P4 info for selected branch" - menu entry */ private JMenuItem createExploreOneMenu() { String command = Commands.COMMAND_EXPLORE_ONE_BRANCH; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("load P4 info for selected branch (if available)"); SimpleAction a = new SimpleAction(command) { public void actionPerformed(ActionEvent e) { if (branchView.getClicked() != null) { Version v = branchView.getClicked().getVersion(); branchView.exploreVersion(v); } } }; mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "collapse / expand one" - menu entry */ private JMenuItem createCollapseOneMenu() { String command = Commands.COMMAND_COLLAPSE_BRANCH; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("collapse / expand 'uninteresting' revisions on this branch"); SimpleAction a = new SimpleAction(command) { public void actionPerformed(ActionEvent e) { if (branchView.getClicked() != null) { branchView.getBranchLayout().toggleCompact(branchView.getClicked()); Action a = (Action) actions.get(Commands.COMMAND_REDO_LAYOUT); a.actionPerformed(new ActionEvent(this, -1, Commands.COMMAND_REDO_LAYOUT)); } } }; mi.addActionListener(a); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "collapse / expand all" - menu entry */ private JMenuItem createCollapseAllMenu() { String command = Commands.COMMAND_COLLAPSE_ALL; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("collapse / expand all 'uninteresting' revisions"); SimpleAction a = new SimpleAction(command) { /** ctrl + e */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { branchView.getBranchLayout().toggleCompact(); Action a = (Action) actions.get(Commands.COMMAND_REDO_LAYOUT); a.actionPerformed(new ActionEvent(this, -1, Commands.COMMAND_REDO_LAYOUT)); } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "save available P4 data" - menu entry */ private JMenuItem createSaveAsTextMenu() { String command = Commands.COMMAND_SAVE_AS_TEXT; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("save available P4 data, i.e. for 'offline' view"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_T; } /** ctrl + t */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { String[] exts = new String[] { "txt", "log" }; String[] desc = new String[] { "textfiles", "logfiles" }; int mode = JFileChooser.SAVE_DIALOG; File[] ff = Toolz.getFilesFromChooser( System.getProperty("user.home"), mode, exts, desc, false, JFileChooser.FILES_ONLY, app.getJComponent()); if (ff.length <= 0) { return; } File f = ff[0]; if (f == null) { return; } else { if (!f.getName().endsWith(".log") && !f.getName().endsWith(".txt")) { f = new File(f.getParentFile(), f.getName() + ".log"); } } try { Toolz.write(app.getConnector().dataToString(), f); } catch (Exception ee) { app.error("Cannot write data to file:\n" + ee.getMessage(), ee); } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "copy P4 depot path" - menu entry */ private JMenuItem createCopyMenu() { String command = Commands.COMMAND_COPY; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("copy P4 depot path to clipboard"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_C; } /** ctrl + c */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { Version v = null; if(branchView.getClicked() != null){ v = branchView.getClicked().getVersion(); } else if(branchView.getDiffView() != null){ v = branchView.getDiffView().getVersion(); } if(v != null){ // this is a bug with clipboard in JDK < 1.4: // content of clipboard is not always really setted content, // but some times content of neighbor memory segment... Toolz.setClipboardContent("" + v.getPath()); } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "copy available P4 data" - menu entry */ private JMenuItem createCopyDataMenu() { String command = Commands.COMMAND_COPY_DATA; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("copy available P4 data as text to clipboard"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_D; } /** ctrl + d */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { Version v = null; if(branchView.getClicked() != null){ v = branchView.getClicked().getVersion(); } else if(branchView.getDiffView() != null){ v = branchView.getDiffView().getVersion(); } if(v != null){ Toolz.setClipboardContent(v.toString()); } else { Toolz.setClipboardContent(app.getConnector().dataToString()); } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "reset all custom user changes" - menu entry */ private JMenuItem createRedoLayoutMenu() { String command = Commands.COMMAND_REDO_LAYOUT; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("reset all custom user changes to layout"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_R; } /** f1 */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { branchView.getBranchLayout().resetUserMoves(); branchView.refreshLayout(true); } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "create one HTML overview file" - menu entry */ private JMenuItem createSaveAsImageMenu() { JMenuItem mi; String command = Commands.COMMAND_SAVE_AS_IMAGE; mi = new JMenuItem(command); mi.setToolTipText("create one HTML overview file with generated GIF images"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_S; } /** ctrl + s */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { String[] exts = new String[] { "html" }; //"jpg", String[] desc = new String[] { "html-files" }; //"jpeg-images", File[] ff = Toolz.getFilesFromChooser( System.getProperty("user.home"), JFileChooser.SAVE_DIALOG, exts, desc, false, JFileChooser.FILES_ONLY, app.getJComponent()); if (ff.length <= 0) { return; } final File f = ff[0]; if (f == null) { return; } else { Thread t = new Thread(new Runnable() { public void run() { branchView.saveViewAsImage(f, panel.getPreferredSize()); } }); t.start(); // workaround for repaint bug panel.repaint(); System.runFinalization(); System.gc(); } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "view/set all available properties" - menu entry */ private JMenuItem createSetPropsMenu() { String command = Commands.COMMAND_SET_PROPS; JMenuItem mi = new JMenuItem(command); mi.setToolTipText("view/set all available properties"); SimpleAction a = new SimpleAction(command) { public int getMnemonic() { return KeyEvent.VK_P; } /** ctrl + p */ public KeyStroke getKeyStroke() { return KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK); } public void actionPerformed(ActionEvent e) { PropertiesPanel props_pnl = panel.getProps_pnl(); if (props_pnl == null) { props_pnl = new PropertiesPanel(app); panel.setProps_pnl(props_pnl); } props_pnl.reset(); if (app.object(props_pnl, "Settings") != null) { props_pnl.setProps(); } } }; mi.addActionListener(a); mi.setAccelerator(a.getKeyStroke()); a.addPropertyChangeListener(new ActionChangedListener(mi)); actions.put(command, a); return mi; } /** * See return description * @return JMenuItem the "view/set all available properties" - menu entry * @return JPanel der "x - space" Schieber */ private JPanel createXSpaceMenu() { JLabel lab; JPanel pan; lab = new JLabel("x space "); lab.setForeground(Color.black); pan = new JPanel(); final JSlider s2 = new JSlider(JSlider.HORIZONTAL, -5, 5, 0); s2.setToolTipText("increase/decrease space between branches"); s2.setMinorTickSpacing(1); s2.setMajorTickSpacing(5); s2.setPaintTicks(true); s2.setSnapToTicks(true); s2.setPreferredSize(new Dimension(200, 40)); s2.setSize(new Dimension(200, 40)); s2.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (!s2.getValueIsAdjusting() || !Toolz.isVmOk()) { Const.H_SPACE = Const.H_SPACE_D + s2.getValue() * Const.STEP_H; branchView.refreshLayout(false); } } }); pan.setLayout(new BorderLayout(2, 2)); pan.add(lab, BorderLayout.EAST); pan.add(s2, BorderLayout.CENTER); return pan; } /** * Method createXSpaceMenu erstellt den "y - space" Schieber * @return JPanel der "y - space" Schieber */ private JPanel createYSpaceMenu() { JLabel lab; JPanel pan; lab = new JLabel("y space "); lab.setForeground(Color.black); pan = new JPanel(); final JSlider s3 = new JSlider(JSlider.HORIZONTAL, -5, 5, 0); s3.setToolTipText("increase/decrease space between revisions"); s3.setMinorTickSpacing(1); s3.setMajorTickSpacing(5); s3.setPaintTicks(true); s3.setSnapToTicks(true); s3.setPreferredSize(new Dimension(200, 40)); s3.setSize(new Dimension(200, 40)); s3.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (!s3.getValueIsAdjusting() || !Toolz.isVmOk()) { Const.V_SPACE = Math.abs(Const.V_SPACE_D + s3.getValue() * Const.STEP_V); branchView.refreshLayout(false); } } }); pan.setLayout(new BorderLayout(2, 2)); pan.add(lab, BorderLayout.EAST); pan.add(s3, BorderLayout.CENTER); return pan; } /** * Method createZoomMenu erstellt den "zoom" Schieber * @return JPanel der "zoom" Schieber */ private JPanel createZoomMenu() { JLabel lab = new JLabel(" zoom "); lab.setForeground(Color.black); JPanel pan = new JPanel(); final JSlider s = new JSlider(JSlider.HORIZONTAL, -5, 5, 0); s.setToolTipText("increase/decrease view zoom"); s.setMinorTickSpacing(1); s.setMajorTickSpacing(5); s.setPaintTicks(true); s.setSnapToTicks(true); s.setPreferredSize(new Dimension(200, 40)); s.setSize(new Dimension(200, 40)); s.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (!s.getValueIsAdjusting() || !Toolz.isVmOk()) { double dx = 1 + (double) (s.getValue() * 0.15); Action act = (Action) actions.get(Commands.COMMAND_ZOOM); act.actionPerformed(new ActionEvent(this, 1, "" + dx)); //zoom(dx,dx); } } }); pan.setLayout(new BorderLayout(2, 2)); pan.add(lab, BorderLayout.EAST); pan.add(s, BorderLayout.CENTER); zoom_slider = s; String command = Commands.COMMAND_ZOOM; SimpleAction a = new SimpleAction(command) { public void actionPerformed(ActionEvent e) { double dx = Double.valueOf(e.getActionCommand()).doubleValue(); if(e.getID() < 0){ // set from keyboard, need to change slider zoom_slider.setValue(zoom_slider.getValue() + (int)dx); } else { panel.zoom(dx,dx); } } }; actions.put(command, a); return pan; } /** * Constructor for MenuCreator. */ public MenuCreator(ViewPanel panel, Configuration app) { super(); this.actions = panel.getActions(); this.app = app; this.branchView = panel.getBranchView(); this.panel = panel; } }
# | 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 |