import java.io.*;\r
import java.awt.image.*;\r
\r
+import gnu.jpdf.*;\r
+\r
\r
public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener, Printable\r
{\r
this.av = av;\r
seqPanel = new SeqPanel (av, this);\r
idPanel = new IdPanel (av, this);\r
+\r
scalePanel = new ScalePanel(av, this);\r
scorePanel = new ScorePanel(av);\r
ssPanel = new SecondaryStructurePanel(av);\r
\r
secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER);\r
- idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
- idPanel.addNotify();\r
\r
- javax.swing.JFrame f = new javax.swing.JFrame();\r
- f.addNotify();\r
- FontMetrics fm = f.getGraphics().getFontMetrics(av.font);\r
- AlignmentI al = av.getAlignment();\r
+ idPanelHolder.add(idPanel, BorderLayout.CENTER);\r
+ IdwidthAdjuster iap = new IdwidthAdjuster(this);\r
+ idSpaceFillerPanel1.add(iap, BorderLayout.CENTER);\r
\r
- int i = 0;\r
- int idWidth = 0;\r
- while (i < al.getHeight() && al.getSequenceAt(i) != null)\r
- {\r
- SequenceI s = al.getSequenceAt(i);\r
- String str = s.getDisplayId();\r
- if (fm.stringWidth(str) > idWidth)\r
- idWidth = fm.stringWidth(str);\r
- i++;\r
- }\r
- hscrollFillerPanel.setPreferredSize(new Dimension(idWidth, 12));\r
+ idPanel.idCanvas.setPreferredSize(calculateIdWidth());\r
+ hscrollFillerPanel.setPreferredSize(calculateIdWidth());\r
\r
scalePanelHolder.add(scalePanel, BorderLayout.CENTER);\r
scorePanelHolder.add(scorePanel, BorderLayout.CENTER);\r
});\r
}\r
\r
+ Dimension calculateIdWidth()\r
+ {\r
+ Graphics g = this.getGraphics();\r
+ if(g==null)\r
+ {\r
+ javax.swing.JFrame f = new javax.swing.JFrame();\r
+ f.addNotify();\r
+ g = f.getGraphics();\r
+ }\r
+\r
+ FontMetrics fm = g.getFontMetrics(av.font);\r
+ AlignmentI al = av.getAlignment();\r
+\r
+ int i = 0;\r
+ int idWidth = 0;\r
+ String id;\r
+ while (i < al.getHeight() && al.getSequenceAt(i) != null)\r
+ {\r
+ SequenceI s = al.getSequenceAt(i);\r
+ if(av.getShowFullId())\r
+ id = s.getDisplayId();\r
+ else\r
+ id = s.getName();\r
+\r
+ if (fm.stringWidth(id) > idWidth)\r
+ idWidth = fm.stringWidth(id);\r
+ i++;\r
+ }\r
+\r
+ return new Dimension(idWidth, 12);\r
+ }\r
+\r
\r
public void highlightSearchResults(int [] results)\r
{\r
\r
hscroll.setVisible(!wrap);\r
\r
- idSpaceFillerPanel.setVisible(!wrap);\r
- idSpaceFillerPanel1.setVisible(!wrap);\r
+ // idSpaceFillerPanel.setVisible(!wrap);\r
+ // idWidthAdjusterPanel.setVisible(!wrap);\r
\r
RefreshPanels();\r
\r
public int printUnwrapped(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException\r
{\r
\r
- int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
+ int idWidth = calculateIdWidth().width;\r
\r
\r
pg.setColor(Color.white);\r
public int printWrappedAlignment(Graphics pg, int pwidth, int pheight, int pi) throws PrinterException\r
{\r
\r
- int idWidth = (int)idPanel.idCanvas.getLabelWidth().getWidth();\r
+ int idWidth = calculateIdWidth().width;\r
\r
if( seqPanel.seqCanvas.getWidth() < pwidth-idWidth)\r
pwidth = seqPanel.seqCanvas.getWidth() + idWidth;\r
\r
\r
\r
+\r