From eee02848424734a9466de35ff19636377652e59b Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 13 Sep 2005 17:44:32 +0000 Subject: [PATCH] EPSOptions added --- src/jalview/gui/AlignmentPanel.java | 39 ++++++++++-- src/jalview/gui/EPSOptions.java | 120 +++++++++++++++++++++++++++++++++++ src/jalview/gui/Preferences.java | 14 +++- src/jalview/gui/TreeCanvas.java | 13 ++-- src/jalview/gui/TreePanel.java | 32 +++++++++- src/jalview/jbgui/GPreferences.java | 114 ++++++++++++++++++--------------- 6 files changed, 265 insertions(+), 67 deletions(-) create mode 100755 src/jalview/gui/EPSOptions.java diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index b3b2865..50c89f5 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -771,6 +771,33 @@ public class AlignmentPanel extends GAlignmentPanel */ public void makeEPS(File epsFile) { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && ! + (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true"))) + { + EPSOptions eps = new EPSOptions(); + renderStyle = eps.getValue(); + + if(eps.cancelled || renderStyle==null) + return; + + renderStyle = eps.getValue(); + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + + if(epsFile == null) { jalview.io.JalviewFileChooser chooser = new jalview.io. @@ -816,12 +843,14 @@ public class AlignmentPanel extends GAlignmentPanel try { - FileOutputStream out = new FileOutputStream(epsFile); - EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, - height); + FileOutputStream out = new FileOutputStream(epsFile); + EpsGraphics2D pg = new EpsGraphics2D("Example", out, 0, 0, width, + height); - if (av.getWrapAlignment()) - { + pg.setAccurateTextMode(accurateText); + + if (av.getWrapAlignment()) + { printWrappedAlignment(pg, width, height, 0); } else diff --git a/src/jalview/gui/EPSOptions.java b/src/jalview/gui/EPSOptions.java new file mode 100755 index 0000000..ee105d8 --- /dev/null +++ b/src/jalview/gui/EPSOptions.java @@ -0,0 +1,120 @@ +package jalview.gui; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class EPSOptions + extends JPanel +{ + JDialog dialog; + boolean cancelled = false; + String value; + + public EPSOptions() + { + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + ButtonGroup bg = new ButtonGroup(); + bg.add(lineart); + bg.add(text); + + JOptionPane pane = new JOptionPane(null, + JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION, + null, new Object[]{this}); + + dialog = pane.createDialog(Desktop.desktop, "EPS Rendering options"); + dialog.show(); + + } + + private void jbInit() + throws Exception + { + lineart.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + lineart.setSelected(true); + lineart.setText("Lineart"); + text.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + text.setText("Text"); + askAgain.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + askAgain.setText("Don\'t ask me again"); + ok.setText("OK"); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText("Cancel"); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + jLabel1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + jLabel1.setText("Select EPS Character rendering style"); + this.setLayout(borderLayout1); + jPanel3.setBorder(BorderFactory.createEtchedBorder()); + jPanel2.add(lineart); + jPanel2.add(text); + jPanel2.add(askAgain); + jPanel1.add(ok); + jPanel1.add(cancel); + jPanel3.add(jLabel1); + jPanel3.add(jPanel2); + this.add(jPanel3, java.awt.BorderLayout.CENTER); + this.add(jPanel1, java.awt.BorderLayout.SOUTH); + } + + JRadioButton lineart = new JRadioButton(); + JRadioButton text = new JRadioButton(); + JCheckBox askAgain = new JCheckBox(); + JButton ok = new JButton(); + JButton cancel = new JButton(); + JPanel jPanel1 = new JPanel(); + JLabel jLabel1 = new JLabel(); + JPanel jPanel2 = new JPanel(); + JPanel jPanel3 = new JPanel(); + BorderLayout borderLayout1 = new BorderLayout(); + + public void ok_actionPerformed(ActionEvent e) + { + if (lineart.isSelected()) + value = "Lineart"; + else + value = "Text"; + + if (!askAgain.isSelected()) + { + jalview.bin.Cache.applicationProperties.remove("EPS_RENDERING"); + } + else + { + jalview.bin.Cache.setProperty("EPS_RENDERING", value); + } + + dialog.hide(); + } + + public void cancel_actionPerformed(ActionEvent e) + { + cancelled = true; + dialog.hide(); + } + + public String getValue() + { + return value; + } +} diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ff44fe4..a6b1066 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -83,9 +83,9 @@ public class Preferences extends GPreferences fullID.setSelected( Cache.getDefault("SHOW_FULL_ID", true)); fullScreen.setSelected( Cache.getDefault("SHOW_FULLSCREEN", false)); - annotations.setSelected( Cache.getDefault("SHOW_FULL_ID", true)); - conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true)); + annotations.setSelected( Cache.getDefault("SHOW_ANNOTATIONS", true)); + conservation.setEnabled( Cache.getDefault("SHOW_ANNOTATIONS", true)); quality.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true)); identity.setEnabled(Cache.getDefault("SHOW_ANNOTATIONS", true)); @@ -137,6 +137,11 @@ public class Preferences extends GPreferences sortby.addItem("Pairwise Identity"); sortby.setSelectedItem( Cache.getDefault("SORT_ALIGNMENT", "No sort") ); + epsRendering.addItem("Prompt each time"); + epsRendering.addItem("Lineart"); + epsRendering.addItem("Text"); + epsRendering.setSelectedItem( Cache.getDefault("EPS_RENDERING", "Prompt each time")); + /**************************************************** * Set up Connections */ @@ -198,6 +203,11 @@ public class Preferences extends GPreferences Cache.applicationProperties.setProperty("SORT_ALIGNMENT", sortby.getSelectedItem().toString() ); + if(epsRendering.getSelectedItem().equals("Prompt each time")) + Cache.applicationProperties.remove("EPS_RENDERING"); + else + Cache.applicationProperties.setProperty("EPS_RENDERING", epsRendering.getSelectedItem().toString()); + if(defaultBrowser.getText().trim().length()<1) Cache.applicationProperties.remove("DEFAULT_BROWSER"); else diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 672d200..eea181f 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -50,7 +50,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, JScrollPane scrollPane; AlignViewport av; Font font; - int fontSize = 12; + int fontSize; boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; @@ -77,6 +77,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, public TreeCanvas(AlignViewport av, JScrollPane scroller) { this.av = av; + font = av.getFont(); scrollPane = scroller; addMouseListener(this); PaintRefresher.Register(this, av.alignment); @@ -523,17 +524,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, public void paintComponent(Graphics g) { super.paintComponent(g); + g.setFont(font); + if(tree==null) { - g.setFont(new Font("Verdana", Font.PLAIN, 18)); g.drawString("Calculating tree....", 20, getHeight()/2); } else { - - font = new Font("Verdana", Font.PLAIN, fontSize); - g.setFont(font); - FontMetrics fm = g.getFontMetrics(font); if (nameHash.size() == 0) @@ -578,6 +576,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, public void setFontSize(int fontSize) { this.fontSize = fontSize; + font = new Font(font.getName(), font.getStyle(), fontSize); repaint(); } @@ -596,6 +595,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, g2.setColor(Color.white); g2.fillRect(0, 0, width, height); + g2.setFont(font); + labelLength = g2.getFontMetrics(font).stringWidth(longestName) + 20; //20 allows for scrollbar float wscale = (float) (width - labelLength - (offx * 2)) / tree.getMaxHeight(); diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java index a05df64..e38e03a 100755 --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@ -370,6 +370,32 @@ public class TreePanel extends GTreePanel */ public void epsTree_actionPerformed(ActionEvent e) { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && ! + (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true"))) + { + EPSOptions eps = new EPSOptions(); + renderStyle = eps.getValue(); + + if (renderStyle==null || eps.cancelled) + return; + + + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + int width = treeCanvas.getWidth(); int height = treeCanvas.getHeight(); @@ -391,11 +417,13 @@ public class TreePanel extends GTreePanel } jalview.bin.Cache.setProperty("LAST_DIRECTORY", - chooser.getSelectedFile().getParent()); + chooser.getSelectedFile().getParent()); FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, - height); + height); + + pg.setAccurateTextMode(accurateText); treeCanvas.draw(pg, width, height); diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index ab1d4e7..320592e 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -84,6 +84,11 @@ public class GPreferences extends JPanel GridBagLayout gridBagLayout3 = new GridBagLayout(); protected JComboBox sortby = new JComboBox(); JLabel sortLabel = new JLabel(); + JPanel jPanel2 = new JPanel(); + GridLayout gridLayout2 = new GridLayout(); + JLabel jLabel1 = new JLabel(); + JPanel jPanel3 = new JPanel(); + protected JComboBox epsRendering = new JComboBox(); /** * Creates a new GPreferences object. */ @@ -129,41 +134,37 @@ public class GPreferences extends JPanel quality.setHorizontalTextPosition(SwingConstants.LEFT); quality.setSelected(true); quality.setText("Quality"); - quality.setBounds(new Rectangle(248, 53, 81, 23)); - visualTab.setBorder(new TitledBorder("Open new alignment")); - visualTab.setBounds(new Rectangle(9, 20, 442, 241)); - visualTab.setLayout(null); + visualTab.setBorder(new TitledBorder("Open new alignment")); + visualTab.setLayout(null); fullID.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); fullID.setHorizontalAlignment(SwingConstants.RIGHT); fullID.setHorizontalTextPosition(SwingConstants.LEFT); - fullID.setText("Full Sequence ID"); - fullID.setBounds(new Rectangle(9, 78, 129, 23)); - fullScreen.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fullID.setMargin(new Insets(4, 2, 2, 0)); + fullID.setText("Full Sequence ID"); + fullScreen.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); fullScreen.setHorizontalAlignment(SwingConstants.RIGHT); fullScreen.setHorizontalTextPosition(SwingConstants.LEFT); - fullScreen.setText("Maximise Window"); - fullScreen.setBounds(new Rectangle(5, 29, 132, 23)); - conservation.setEnabled(false); + fullScreen.setMargin(new Insets(2, 2, 2, 0)); + fullScreen.setText("Maximise Window"); + conservation.setEnabled(false); conservation.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); conservation.setHorizontalAlignment(SwingConstants.RIGHT); conservation.setHorizontalTextPosition(SwingConstants.LEFT); conservation.setSelected(true); conservation.setText("Conservation"); - conservation.setBounds(new Rectangle(137, 53, 113, 23)); - identity.setEnabled(false); + identity.setEnabled(false); identity.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); identity.setHorizontalAlignment(SwingConstants.RIGHT); identity.setHorizontalTextPosition(SwingConstants.LEFT); identity.setSelected(true); identity.setText("Consensus"); - identity.setBounds(new Rectangle(326, 53, 99, 23)); - annotations.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + annotations.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); annotations.setHorizontalAlignment(SwingConstants.RIGHT); annotations.setHorizontalTextPosition(SwingConstants.LEFT); - annotations.setSelected(true); + annotations.setMargin(new Insets(2, 4, 2, 0)); + annotations.setSelected(true); annotations.setText("Show Annotations"); - annotations.setBounds(new Rectangle(10, 53, 128, 23)); - annotations.addActionListener(new ActionListener() + annotations.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -173,33 +174,29 @@ public class GPreferences extends JPanel gapLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); gapLabel.setHorizontalAlignment(SwingConstants.RIGHT); gapLabel.setText("Gap Symbol"); - gapLabel.setBounds(new Rectangle(41, 142, 76, 15)); - colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - colour.setBounds(new Rectangle(121, 168, 154, 21)); + colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + colour.setBounds(new Rectangle(154, 151, 154, 21)); colourLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); colourLabel.setHorizontalAlignment(SwingConstants.RIGHT); colourLabel.setText("Colour"); - colourLabel.setBounds(new Rectangle(60, 172, 58, 15)); - fontLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); fontLabel.setHorizontalAlignment(SwingConstants.RIGHT); fontLabel.setText("Font"); - fontLabel.setBounds(new Rectangle(83, 114, 34, 15)); - fontSizeCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - fontSizeCB.setBounds(new Rectangle(304, 109, 49, 21)); + fontSizeCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + fontSizeCB.setBounds(new Rectangle(322, 98, 49, 21)); fontStyleCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - fontStyleCB.setBounds(new Rectangle(353, 109, 80, 21)); + fontStyleCB.setBounds(new Rectangle(370, 98, 70, 21)); fontNameCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - fontNameCB.setBounds(new Rectangle(121, 109, 183, 21)); + fontNameCB.setBounds(new Rectangle(153, 98, 169, 21)); gapSymbolCB.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - gapSymbolCB.setBounds(new Rectangle(121, 140, 67, 21)); + gapSymbolCB.setBounds(new Rectangle(154, 125, 67, 21)); startupCheckbox.setText("Open file"); - startupCheckbox.setBounds(new Rectangle(4, 200, 115, 23)); - startupCheckbox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + startupCheckbox.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); startupCheckbox.setHorizontalAlignment(SwingConstants.RIGHT); startupCheckbox.setHorizontalTextPosition(SwingConstants.LEFT); startupCheckbox.setSelected(true); startupFileTextfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - startupFileTextfield.setBounds(new Rectangle(121, 200, 309, 20)); + startupFileTextfield.setBounds(new Rectangle(154, 204, 285, 20)); startupFileTextfield.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) @@ -297,32 +294,41 @@ public class GPreferences extends JPanel jPanel1.setBorder(titledBorder1); jPanel1.setLayout(gridBagLayout1); sortby.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); - sortby.setBounds(new Rectangle(122, 232, 308, 21)); + sortby.setBounds(new Rectangle(154, 178, 286, 21)); sortLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); sortLabel.setHorizontalAlignment(SwingConstants.RIGHT); sortLabel.setText("Sort by"); - sortLabel.setBounds(new Rectangle(53, 235, 64, 15)); - visualTab.add(annotations); - visualTab.add(conservation); - visualTab.add(quality); - visualTab.add(fullID); - visualTab.add(gapSymbolCB); - visualTab.add(fontLabel); - visualTab.add(fontNameCB); - visualTab.add(colourLabel); - visualTab.add(gapLabel); + jPanel2.setBounds(new Rectangle(7, 19, 141, 242)); + jPanel2.setLayout(gridLayout2); + gridLayout2.setRows(9); + jLabel1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + jLabel1.setHorizontalAlignment(SwingConstants.RIGHT); + jLabel1.setText("EPS Rendering Style"); + jPanel3.setBounds(new Rectangle(149, 42, 278, 26)); + epsRendering.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); + epsRendering.setBounds(new Rectangle(154, 228, 286, 21)); + jPanel2.add(fullScreen); + jPanel2.add(annotations); + jPanel2.add(fullID); + jPanel2.add(fontLabel); + jPanel2.add(gapLabel); + jPanel2.add(colourLabel); + jPanel2.add(sortLabel); + jPanel2.add(startupCheckbox); + jPanel2.add(jLabel1); + visualTab.add(jPanel3); + jPanel3.add(conservation); + jPanel3.add(quality); + jPanel3.add(identity); + visualTab.add(fontNameCB); + visualTab.add(fontSizeCB); + visualTab.add(fontStyleCB); + visualTab.add(gapSymbolCB); visualTab.add(colour); - visualTab.add(fontSizeCB); - visualTab.add(fontStyleCB); - visualTab.add(identity); - visualTab.add(fullScreen); - visualTab.add(startupCheckbox); - visualTab.add(startupFileTextfield); visualTab.add(sortby); - visualTab.add(sortLabel); - - tabbedPane.add(visualTab, "Visual"); - tabbedPane.add(connectTab, "Connections"); + visualTab.add(startupFileTextfield); + visualTab.add(epsRendering); + visualTab.add(jPanel2); linkPanel.add(editLinkButtons, BorderLayout.EAST); editLinkButtons.add(newLink, null); @@ -362,6 +368,7 @@ public class GPreferences extends JPanel connectTab.add(defaultBrowser, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0 , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 0, 0, 15), 307, 1)); + jPanel1.add(useProxy, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0 , GridBagConstraints.WEST, GridBagConstraints.NONE, @@ -370,6 +377,9 @@ public class GPreferences extends JPanel DefaultListCellRenderer dlcr = new DefaultListCellRenderer(); dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER); gapSymbolCB.setRenderer(dlcr); + + tabbedPane.add(visualTab, "Visual"); + tabbedPane.add(connectTab, "Connections"); } /** -- 1.7.10.2