rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
log.warn( "Property changed: " + (String) field ); System.out.println( "Property changed: " + (String) field );
log.debug( "Property changed: " + (String) field );
public void propertyChange( PropertyChangeEvent ev ) { if ( ev.getPropertyName().equals( "value" ) ) { Object src = ev.getSource(); if ( src.getClass() == JFormattedTextField.class ) { Object field = ((JFormattedTextField) src).getClientProperty( FIELD_NAME ); Object value = ((JFormattedTextField) src).getValue(); /* Field value is set to null (as it is when ctrl is controlling multiple photos which have differing value for te field) this is called every time the field is accessed, so we must not notify the controller. After the user has actually set the value it is no longer null. */ if ( value != null ) { log.warn( "Property changed: " + (String) field ); System.out.println( "Property changed: " + (String) field ); ctrl.viewChanged( this, (String) field ); } } } }
qualityField.setSelectedIndex( 0 );
qualityField.setSelectedIndex( -1 );
public void setQuality( Number quality ) { if ( quality != null ) { qualityField.setSelectedIndex( quality.intValue() ); } else { qualityField.setSelectedIndex( 0 ); } }
registerTag( "focusListener", FocusListenerTag.class ); registerTag( "keyListener", KeyListenerTag.class );
public SwingTagLibrary() { registerTag( "action", ActionTag.class ); registerTag( "font", FontTag.class ); registerTag( "windowListener", WindowListenerTag.class ); // the model tags registerTag( "tableModel", TableModelTag.class ); registerTag( "tableModelColumn", TableModelColumnTag.class ); // the border tags... registerTag( "titledBorder", TitledBorderTag.class ); // @todo the other kinds of borders, empty, bevelled, compound etc // the layout tags... // HTML style table, tr, td layouts registerTag( "tableLayout", TableLayoutTag.class ); registerTag( "tr", TrTag.class ); registerTag( "td", TdTag.class ); // GridBagLayout registerTag( "gridBagLayout", GridBagLayoutTag.class ); registerTag( "gbc", GbcTag.class ); // BorderLayout registerTag( "borderLayout", BorderLayoutTag.class ); registerTag( "borderAlign", BorderAlignTag.class ); // Dialog registerTag( "dialog", DialogTag.class ); }
if (getSQLObjectListeners().contains(l)) { if (logger.isDebugEnabled()) { logger.debug("NOT Adding duplicate listener "+l+" to SQLObject "+this); } return;
synchronized(sqlObjectListeners) { if (sqlObjectListeners.contains(l)) { if (logger.isDebugEnabled()) { logger.debug("NOT Adding duplicate listener "+l+" to SQLObject "+this); } return; } sqlObjectListeners.add(l);
public void addSQLObjectListener(SQLObjectListener l) { if (l == null) throw new NullPointerException("You can't add a null listener"); if (getSQLObjectListeners().contains(l)) { if (logger.isDebugEnabled()) { logger.debug("NOT Adding duplicate listener "+l+" to SQLObject "+this); } return; } getSQLObjectListeners().add(l); }
getSQLObjectListeners().add(l);
public void addSQLObjectListener(SQLObjectListener l) { if (l == null) throw new NullPointerException("You can't add a null listener"); if (getSQLObjectListeners().contains(l)) { if (logger.isDebugEnabled()) { logger.debug("NOT Adding duplicate listener "+l+" to SQLObject "+this); } return; } getSQLObjectListeners().add(l); }
Iterator it = getSQLObjectListeners().iterator(); int count = 0; while (it.hasNext()) { count ++; ((SQLObjectListener) it.next()).dbChildrenInserted(e);
synchronized(sqlObjectListeners) { Iterator<SQLObjectListener> it = sqlObjectListeners.iterator(); int count = 0; while (it.hasNext()) { count ++; SQLObjectListener nextListener = it.next(); (nextListener).dbChildrenInserted(e); } logger.debug(getClass().getName()+": notified "+count+" listeners");
protected void fireDbChildrenInserted(int[] newIndices, List newChildren) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbChildrenInserted event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent (this, newIndices, (SQLObject[]) newChildren.toArray(new SQLObject[newChildren.size()]), isSecondaryChangeMode()); Iterator it = getSQLObjectListeners().iterator(); int count = 0; while (it.hasNext()) { count ++; ((SQLObjectListener) it.next()).dbChildrenInserted(e); } logger.debug(getClass().getName()+": notified "+count+" listeners"); }
logger.debug(getClass().getName()+": notified "+count+" listeners");
protected void fireDbChildrenInserted(int[] newIndices, List newChildren) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbChildrenInserted event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent (this, newIndices, (SQLObject[]) newChildren.toArray(new SQLObject[newChildren.size()]), isSecondaryChangeMode()); Iterator it = getSQLObjectListeners().iterator(); int count = 0; while (it.hasNext()) { count ++; ((SQLObjectListener) it.next()).dbChildrenInserted(e); } logger.debug(getClass().getName()+": notified "+count+" listeners"); }
Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { ((SQLObjectListener) it.next()).dbChildrenRemoved(e);
synchronized(sqlObjectListeners) { Iterator it = sqlObjectListeners.iterator(); while (it.hasNext()) { ((SQLObjectListener) it.next()).dbChildrenRemoved(e); }
protected void fireDbChildrenRemoved(int[] oldIndices, List oldChildren) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbChildrenRemoved event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent (this, oldIndices, (SQLObject[]) oldChildren.toArray(new SQLObject[oldChildren.size()]), isSecondaryChangeMode()); Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { ((SQLObjectListener) it.next()).dbChildrenRemoved(e); } }
Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbObjectChanged(e);
synchronized(sqlObjectListeners) { Iterator it = sqlObjectListeners.iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbObjectChanged(e); }
protected void fireDbObjectChanged(String propertyName, Object oldValue, Object newValue) { SQLObjectEvent e = new SQLObjectEvent( this, propertyName, oldValue, newValue, isSecondaryChangeMode()); boolean same = (oldValue == null ? oldValue == newValue : oldValue.equals(newValue)); if (same) { logger.debug("Object changed event aborted, the old value '"+oldValue+"' of " +propertyName+" equals the new value '"+newValue+"'"); return; } if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbObjectChanged event " + "(secondary = "+isSecondaryChangeMode()+")"); } int count = 0; Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbObjectChanged(e); } if (logger.isDebugEnabled()) logger.debug("Notified "+count+" listeners."); }
protected void fireDbStructureChanged(String propertyName) {
public void fireDbStructureChanged() {
protected void fireDbStructureChanged(String propertyName) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbStructureChanged event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent( this, propertyName, isSecondaryChangeMode()); int count = 0; Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbStructureChanged(e); } if (logger.isDebugEnabled()) logger.debug("Notified "+count+" listeners."); }
propertyName,
null,
protected void fireDbStructureChanged(String propertyName) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbStructureChanged event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent( this, propertyName, isSecondaryChangeMode()); int count = 0; Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbStructureChanged(e); } if (logger.isDebugEnabled()) logger.debug("Notified "+count+" listeners."); }
Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbStructureChanged(e);
synchronized(sqlObjectListeners) { Iterator it = sqlObjectListeners.iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbStructureChanged(e); }
protected void fireDbStructureChanged(String propertyName) { if (logger.isDebugEnabled()) { logger.debug(getClass().getName()+" "+toString()+": " + "firing dbStructureChanged event " + "(secondary = "+isSecondaryChangeMode()+")"); } SQLObjectEvent e = new SQLObjectEvent( this, propertyName, isSecondaryChangeMode()); int count = 0; Iterator it = getSQLObjectListeners().iterator(); while (it.hasNext()) { count++; ((SQLObjectListener) it.next()).dbStructureChanged(e); } if (logger.isDebugEnabled()) logger.debug("Notified "+count+" listeners."); }
public List getSQLObjectListeners() { if (sqlObjectListeners == null) { sqlObjectListeners = new LinkedList(); } return sqlObjectListeners;
public List<SQLObjectListener> getSQLObjectListeners() { return sqlObjectListeners;
public List getSQLObjectListeners() { if (sqlObjectListeners == null) { sqlObjectListeners = new LinkedList(); } return sqlObjectListeners; }
getSQLObjectListeners().remove(l);
synchronized(sqlObjectListeners) { sqlObjectListeners.remove(l); }
public void removeSQLObjectListener(SQLObjectListener l) { getSQLObjectListeners().remove(l); }
if (! hasTrimmed) { hasTrimmed = true; if (isTrim()) { trimBody(); } }
public Script getBody() { return body; }
if ( isTrim() && ! hasTrimmed ) { trimBody(); }
public void invokeBody(XMLOutput output) throws Exception { if ( isTrim() && ! hasTrimmed ) { trimBody(); } getBody().run(context, output); }
this.hasTrimmed = true;
protected void trimBody() { // #### should refactor this code into // #### trimWhitespace() methods on the Script objects if ( body instanceof CompositeTextScriptBlock ) { CompositeTextScriptBlock block = (CompositeTextScriptBlock) body; List list = block.getScriptList(); int size = list.size(); if ( size > 0 ) { Script script = (Script) list.get(0); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimStartWhitespace(); } if ( size > 1 ) { script = (Script) list.get(size - 1); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; textScript.trimEndWhitespace(); } } } } else if ( body instanceof ScriptBlock ) { ScriptBlock block = (ScriptBlock) body; List list = block.getScriptList(); for ( int i = list.size() - 1; i >= 0; i-- ) { Script script = (Script) list.get(i); if ( script instanceof TextScript ) { TextScript textScript = (TextScript) script; String text = textScript.getText(); text = text.trim(); if ( text.length() == 0 ) { list.remove(i); } else { textScript.setText(text); } } } } else if ( body instanceof TextScript ) { TextScript textScript = (TextScript) body; textScript.trimWhitespace(); } this.hasTrimmed = true; }
for(Iterator it=mbeanList.iterator(); it.hasNext();){ MBeanConfig mbeanConfig = (MBeanConfig)it.next(); if(mbeanConfig.getObjectName().equals(objectName)){ return true; } } return false;
return findMBeanByObjectName(objectName) != null;
public boolean containsMBean(String objectName) { for(Iterator it=mbeanList.iterator(); it.hasNext();){ MBeanConfig mbeanConfig = (MBeanConfig)it.next(); if(mbeanConfig.getObjectName().equals(objectName)){ return true; } } return false; }
public BaseObject getFirstObject(String fieldname, XWikiContext context) { Collection objectscoll = getxWikiObjects().values(); if (objectscoll == null) return null; for (Iterator itobjs = objectscoll.iterator(); itobjs.hasNext();) { Vector objects = (Vector) itobjs.next(); for (Iterator itobjs2 = objects.iterator(); itobjs2.hasNext();) { BaseObject obj = (BaseObject) itobjs2.next(); if (obj != null) { BaseClass bclass = obj.getxWikiClass(context); if (bclass!=null) { Set set = bclass.getPropertyList(); if ((set != null) && set.contains(fieldname)) return obj; } Set set = obj.getPropertyList(); if ((set != null) && set.contains(fieldname)) return obj; } } } return null;
public BaseObject getFirstObject(String fieldname) { return getFirstObject(fieldname, null);
public BaseObject getFirstObject(String fieldname, XWikiContext context) { Collection objectscoll = getxWikiObjects().values(); if (objectscoll == null) return null; for (Iterator itobjs = objectscoll.iterator(); itobjs.hasNext();) { Vector objects = (Vector) itobjs.next(); for (Iterator itobjs2 = objects.iterator(); itobjs2.hasNext();) { BaseObject obj = (BaseObject) itobjs2.next(); if (obj != null) { BaseClass bclass = obj.getxWikiClass(context); if (bclass!=null) { Set set = bclass.getPropertyList(); if ((set != null) && set.contains(fieldname)) return obj; } Set set = obj.getPropertyList(); if ((set != null) && set.contains(fieldname)) return obj; } } } return null; }
if (!dashboardId.equals(dashboardConfig.dashboardId)) return false; return true;
return dashboardId.equals(dashboardConfig.dashboardId);
public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DashboardConfig)) return false; final DashboardConfig dashboardConfig = (DashboardConfig) o; if (!dashboardId.equals(dashboardConfig.dashboardId)) return false; return true; }
public static boolean isKnownDataType(Class clazz){ if(clazz.isPrimitive() || clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(Byte.class) || clazz.isAssignableFrom(Short.class) || clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(Void.class) || clazz.isAssignableFrom(String.class) || clazz.isAssignableFrom(BigInteger.class) || clazz.isAssignableFrom(BigDecimal.class) || clazz.isAssignableFrom(Date.class)){
public static boolean isKnownDataType(String type){ if(type.equals("boolean") || type.equals("char") || type.equals("byte") || type.equals("short") || type.equals("int") || type.equals("long") || type.equals("float") || type.equals("double") || type.equals("void") || type.equals("java.lang.Boolean") || type.equals("java.lang.Character") || type.equals("java.lang.Byte") || type.equals("java.lang.Short") || type.equals("java.lang.Integer") || type.equals("java.lang.Long") || type.equals("java.lang.Float") || type.equals("java.lang.Double") || type.equals("java.lang.Void") || type.equals("java.lang.String") || type.equals("java.math.BigInteger") || type.equals("java.math.BigDecimal") || type.equals("java.util.Date")){
public static boolean isKnownDataType(Class clazz){ if(clazz.isPrimitive() || clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(Byte.class) || clazz.isAssignableFrom(Short.class) || clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(Void.class) || clazz.isAssignableFrom(String.class) || clazz.isAssignableFrom(BigInteger.class) || clazz.isAssignableFrom(BigDecimal.class) || clazz.isAssignableFrom(Date.class)){ return true; } return false; }
value = expression.evaluate(context);
value = expression.evaluateRecurse(context);
public void run(JellyContext context, XMLOutput output) throws Exception { if ( ! context.isCacheTags() ) { clearTag(); } try { Tag tag = getTag(); if ( tag == null ) { return; } tag.setContext(context); if ( tag instanceof DynaTag ) { DynaTag dynaTag = (DynaTag) tag; // ### probably compiling this to 2 arrays might be quicker and smaller for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Expression expression = (Expression) entry.getValue(); Class type = dynaTag.getAttributeType(name); Object value = null; if (type != null && type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) { value = expression; } else { value = expression.evaluate(context); } dynaTag.setAttribute(name, value); } } else { // treat the tag as a bean DynaBean dynaBean = new ConvertingWrapDynaBean( tag ); for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Expression expression = (Expression) entry.getValue(); DynaProperty property = dynaBean.getDynaClass().getDynaProperty(name); if (property == null) { throw new JellyException("This tag does not understand the '" + name + "' attribute" ); } Class type = property.getType(); Object value = null; if (type.isAssignableFrom(Expression.class) && !type.isAssignableFrom(Object.class)) { value = expression; } else { value = expression.evaluate(context); } dynaBean.set(name, value); } } tag.doTag(output); } catch (JellyException e) { handleException(e); } catch (Exception e) { handleException(e); } catch (Error e) { handleException(e); } }
}, null);
}, new AbstractAction(){ public void actionPerformed(ActionEvent e) { columnEditPanel.discardChanges(); } });
private void makeDialog(SQLTable st, int colIdx) throws ArchitectException { if (editDialog != null) { columnEditPanel.setModel(st); columnEditPanel.selectColumn(colIdx); editDialog.setTitle("Column Properties of "+st.getName()); editDialog.setVisible(true); //editDialog.requestFocus(); } else { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout(12,12)); panel.setBorder(BorderFactory.createEmptyBorder(12,12,12,12)); columnEditPanel = new ColumnEditPanel(st, colIdx); panel.add(columnEditPanel, BorderLayout.CENTER); editDialog = ArchitectPanelBuilder.createArchitectPanelDialog( columnEditPanel, ArchitectFrame.getMainInstance(), "Column Properties of "+st.getName(), "OK", new AbstractAction(){ public void actionPerformed(ActionEvent e) { columnEditPanel.applyChanges(); EditColumnAction.this.putValue(SHORT_DESCRIPTION, "Editting "+columnEditPanel.getColName().getText() ); } }, null); panel.setOpaque(true); editDialog.pack(); editDialog.setLocationRelativeTo(ArchitectFrame.getMainInstance()); editDialog.setVisible(true); } }
WeblogicApplicationForm appForm = (WeblogicApplicationForm)actionForm;
ApplicationForm appForm = (ApplicationForm)actionForm; ModuleConfig moduleConfig = ModuleRegistry.getModule(config.getType()); MetaApplicationConfig metaAppConfig = moduleConfig.getMetaApplicationConfig();
public ActionForward execute(WebContext context, ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { ApplicationConfig config = context.getApplicationConfig(); WeblogicApplicationForm appForm = (WeblogicApplicationForm)actionForm; /* populate the form */ appForm.setApplicationId(config.getApplicationId()); appForm.setName(config.getName()); appForm.setHost(config.getHost()); appForm.setPort(String.valueOf(config.getPort())); appForm.setUsername(config.getUsername()); appForm.setPassword(ApplicationForm.FORM_PASSWORD); return mapping.findForward(Forwards.SUCCESS); }
appForm.setHost(config.getHost()); appForm.setPort(String.valueOf(config.getPort())); appForm.setUsername(config.getUsername()); appForm.setPassword(ApplicationForm.FORM_PASSWORD);
appForm.setType(config.getType()); if(metaAppConfig.isDisplayHost()) appForm.setHost(config.getHost()); if(metaAppConfig.isDisplayPort()) appForm.setPort(String.valueOf(config.getPort())); if(metaAppConfig.isDisplayUsername()) appForm.setUsername(config.getUsername()); if(metaAppConfig.isDisplayPassword()) appForm.setPassword(ApplicationForm.FORM_PASSWORD); request.setAttribute(RequestAttributes.META_APP_CONFIG, metaAppConfig);
public ActionForward execute(WebContext context, ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { ApplicationConfig config = context.getApplicationConfig(); WeblogicApplicationForm appForm = (WeblogicApplicationForm)actionForm; /* populate the form */ appForm.setApplicationId(config.getApplicationId()); appForm.setName(config.getName()); appForm.setHost(config.getHost()); appForm.setPort(String.valueOf(config.getPort())); appForm.setUsername(config.getUsername()); appForm.setPassword(ApplicationForm.FORM_PASSWORD); return mapping.findForward(Forwards.SUCCESS); }
checkPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
void readPedGenotypes(String[] f){ //input is a 3 element array with //inputOptions[0] = ped file //inputOptions[1] = info file (null if none) //inputOptions[2] = max comparison distance (don't compute d' if markers are greater than this dist apart) inputOptions = f; File pedFile = new File(inputOptions[0]); //pop open checkdata window //checkWindow = new JFrame(); try { checkPanel = new CheckDataPanel(pedFile); }catch(IOException ioexec) { JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } //checkWindow.setTitle("Checking markers..." + pedFile.getName()); //JPanel metaCheckPanel = new JPanel(); //metaCheckPanel.setLayout(new BoxLayout(metaCheckPanel, BoxLayout.Y_AXIS)); //JButton checkContinueButton = new JButton("Continue"); //checkContinueButton.addActionListener(this); checkPanel.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(checkPanel); //checkContinueButton.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(checkContinueButton); //JLabel infoLabel = new JLabel("(this will create a haplotype file named " + pedFile.getName() + ".haps)"); //infoLabel.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(infoLabel); //checkWindow.setContentPane(metaCheckPanel); //checkWindow.pack(); //checkWindow.setVisible(true); theData = new HaploData(); JTable table = checkPanel.getTable(); //checkWindow.dispose(); boolean[] markerResultArray = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResultArray[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } /* try{ new TextMethods().linkageToHaps(markerResultArray,checkPanel.getPedFile(),inputOptions[0]+".haps"); }catch (IOException ioexec){ JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } */ theData.linkageToChrom(markerResultArray,checkPanel.getPedFile()); this.doTDT = true; processData(); //processInput(new File(hapInputFileName+".haps")); }
theData = new HaploData(); JTable table = checkPanel.getTable(); boolean[] markerResultArray = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResultArray[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } theData.linkageToChrom(markerResultArray,checkPanel.getPedFile()); this.doTDT = true; processData();
void readPedGenotypes(String[] f){ //input is a 3 element array with //inputOptions[0] = ped file //inputOptions[1] = info file (null if none) //inputOptions[2] = max comparison distance (don't compute d' if markers are greater than this dist apart) inputOptions = f; File pedFile = new File(inputOptions[0]); //pop open checkdata window //checkWindow = new JFrame(); try { checkPanel = new CheckDataPanel(pedFile); }catch(IOException ioexec) { JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } //checkWindow.setTitle("Checking markers..." + pedFile.getName()); //JPanel metaCheckPanel = new JPanel(); //metaCheckPanel.setLayout(new BoxLayout(metaCheckPanel, BoxLayout.Y_AXIS)); //JButton checkContinueButton = new JButton("Continue"); //checkContinueButton.addActionListener(this); checkPanel.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(checkPanel); //checkContinueButton.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(checkContinueButton); //JLabel infoLabel = new JLabel("(this will create a haplotype file named " + pedFile.getName() + ".haps)"); //infoLabel.setAlignmentX(Component.CENTER_ALIGNMENT); //metaCheckPanel.add(infoLabel); //checkWindow.setContentPane(metaCheckPanel); //checkWindow.pack(); //checkWindow.setVisible(true); theData = new HaploData(); JTable table = checkPanel.getTable(); //checkWindow.dispose(); boolean[] markerResultArray = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResultArray[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } /* try{ new TextMethods().linkageToHaps(markerResultArray,checkPanel.getPedFile(),inputOptions[0]+".haps"); }catch (IOException ioexec){ JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } */ theData.linkageToChrom(markerResultArray,checkPanel.getPedFile()); this.doTDT = true; processData(); //processInput(new File(hapInputFileName+".haps")); }
if (size.width != pref.width && size.width > visRect.width){
if (size.width != pref.width && pref.width > visRect.width){
public void stateChanged(ChangeEvent e) { int tabNum = tabs.getSelectedIndex(); if (tabNum == VIEW_D_NUM || tabNum == VIEW_HAP_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(true); }else if (tabNum == VIEW_TDT_NUM || tabNum == VIEW_CHECK_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(false); }else{ exportMenuItems[0].setEnabled(false); exportMenuItems[1].setEnabled(false); } viewMenuItems[tabs.getSelectedIndex()].setSelected(true); if (checkPanel != null && checkPanel.changed){ window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JTable table = checkPanel.getTable(); boolean[] markerResults = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResults[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } int count = 0; for (int i = 0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ count++; } } Chromosome.realIndex = new int[count]; int k = 0; for (int i =0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ Chromosome.realIndex[k] = i; k++; } } theData.filteredDPrimeTable = theData.getFilteredTable(); theData.guessBlocks(currentBlockDef); //after editing the filtered marker list, needs to be prodded into //resizing correctly Dimension size = dPrimeDisplay.getSize(); Dimension pref = dPrimeDisplay.getPreferredSize(); Rectangle visRect = dPrimeDisplay.getVisibleRect(); if (size.width != pref.width && size.width > visRect.width){ ((JViewport)dPrimeDisplay.getParent()).setViewSize(pref); } dPrimeDisplay.refresh(0); hapDisplay.theData = theData; try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } tdtPanel.refreshTable(); //System.out.println(tabs.getComponentAt(VIEW_TDT_NUM)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); checkPanel.changed=false; } if (hapDisplay != null && theData.blocksChanged){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } hapScroller.setViewportView(hapDisplay); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); theData.blocksChanged = false; } }
dPrimeDisplay.refresh(0);
dPrimeDisplay.refresh(dPrimeDisplay.currentScheme);
public void stateChanged(ChangeEvent e) { int tabNum = tabs.getSelectedIndex(); if (tabNum == VIEW_D_NUM || tabNum == VIEW_HAP_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(true); }else if (tabNum == VIEW_TDT_NUM || tabNum == VIEW_CHECK_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(false); }else{ exportMenuItems[0].setEnabled(false); exportMenuItems[1].setEnabled(false); } viewMenuItems[tabs.getSelectedIndex()].setSelected(true); if (checkPanel != null && checkPanel.changed){ window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JTable table = checkPanel.getTable(); boolean[] markerResults = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResults[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } int count = 0; for (int i = 0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ count++; } } Chromosome.realIndex = new int[count]; int k = 0; for (int i =0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ Chromosome.realIndex[k] = i; k++; } } theData.filteredDPrimeTable = theData.getFilteredTable(); theData.guessBlocks(currentBlockDef); //after editing the filtered marker list, needs to be prodded into //resizing correctly Dimension size = dPrimeDisplay.getSize(); Dimension pref = dPrimeDisplay.getPreferredSize(); Rectangle visRect = dPrimeDisplay.getVisibleRect(); if (size.width != pref.width && size.width > visRect.width){ ((JViewport)dPrimeDisplay.getParent()).setViewSize(pref); } dPrimeDisplay.refresh(0); hapDisplay.theData = theData; try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } tdtPanel.refreshTable(); //System.out.println(tabs.getComponentAt(VIEW_TDT_NUM)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); checkPanel.changed=false; } if (hapDisplay != null && theData.blocksChanged){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } hapScroller.setViewportView(hapDisplay); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); theData.blocksChanged = false; } }
tdtPanel.refreshTable();
if (tdtPanel != null){ tdtPanel.refreshTable(); }
public void stateChanged(ChangeEvent e) { int tabNum = tabs.getSelectedIndex(); if (tabNum == VIEW_D_NUM || tabNum == VIEW_HAP_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(true); }else if (tabNum == VIEW_TDT_NUM || tabNum == VIEW_CHECK_NUM){ exportMenuItems[0].setEnabled(true); exportMenuItems[1].setEnabled(false); }else{ exportMenuItems[0].setEnabled(false); exportMenuItems[1].setEnabled(false); } viewMenuItems[tabs.getSelectedIndex()].setSelected(true); if (checkPanel != null && checkPanel.changed){ window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JTable table = checkPanel.getTable(); boolean[] markerResults = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResults[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } int count = 0; for (int i = 0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ count++; } } Chromosome.realIndex = new int[count]; int k = 0; for (int i =0; i < Chromosome.getSize(); i++){ if (markerResults[i]){ Chromosome.realIndex[k] = i; k++; } } theData.filteredDPrimeTable = theData.getFilteredTable(); theData.guessBlocks(currentBlockDef); //after editing the filtered marker list, needs to be prodded into //resizing correctly Dimension size = dPrimeDisplay.getSize(); Dimension pref = dPrimeDisplay.getPreferredSize(); Rectangle visRect = dPrimeDisplay.getVisibleRect(); if (size.width != pref.width && size.width > visRect.width){ ((JViewport)dPrimeDisplay.getParent()).setViewSize(pref); } dPrimeDisplay.refresh(0); hapDisplay.theData = theData; try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } tdtPanel.refreshTable(); //System.out.println(tabs.getComponentAt(VIEW_TDT_NUM)); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); checkPanel.changed=false; } if (hapDisplay != null && theData.blocksChanged){ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try{ hapDisplay.getHaps(); }catch(HaploViewException hv){ JOptionPane.showMessageDialog(window, hv.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } hapScroller.setViewportView(hapDisplay); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); theData.blocksChanged = false; } }
System.setProperty("swing.disableFileChooserSpeedFix", "true");
public static void main(String[] args) { boolean nogui = false; //HaploView window; for(int i = 0;i<args.length;i++) { if(args[i].equals("-n") || args[i].equals("-h")) { nogui = true; } } if(nogui) { HaploText textOnly = new HaploText(args); } else { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { } System.setProperty("swing.disableFileChooserSpeedFix", "true"); window = new HaploView(); window.argHandler(args); //setup view object window.setTitle("HaploView beta"); window.setSize(800,600); //center the window on the screen Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((screen.width - window.getWidth()) / 2, (screen.height - window.getHeight()) / 2); window.setVisible(true); ReadDataDialog readDialog = new ReadDataDialog("Welcome to HaploView", window); readDialog.pack(); readDialog.setVisible(true); } }
if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes);
if(assocTest > 0) { tdtPanel = new TDTPanel(theData.chromosomes, assocTest);
void processData() { maxCompDist = Long.parseLong(inputOptions[2])*1000; this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final SwingWorker worker = new SwingWorker(){ public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); colorMenuItems[0].setSelected(true); colorMenuItems[1].setEnabled(true); theData.blocksChanged = false; Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); viewMenuItems[VIEW_D_NUM].setEnabled(true); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); viewMenuItems[VIEW_HAP_NUM].setEnabled(true); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } //TDT panel if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); viewMenuItems[VIEW_TDT_NUM].setEnabled(true); } tabs.setSelectedIndex(currentTab); contents.add(tabs); repaint(); setVisible(true); theData.finished = true; return null; } }; timer = new javax.swing.Timer(50, new ActionListener(){ public void actionPerformed(ActionEvent evt){ if (theData.finished){ timer.stop(); for (int i = 0; i < blockMenuItems.length; i++){ blockMenuItems[i].setEnabled(true); } clearBlocksItem.setEnabled(true); readMarkerItem.setEnabled(true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } }); worker.start(); timer.start(); }
if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes);
if(assocTest > 0) { tdtPanel = new TDTPanel(theData.chromosomes, assocTest);
public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); colorMenuItems[0].setSelected(true); colorMenuItems[1].setEnabled(true); theData.blocksChanged = false; Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); viewMenuItems[VIEW_D_NUM].setEnabled(true); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); viewMenuItems[VIEW_HAP_NUM].setEnabled(true); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } //TDT panel if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); viewMenuItems[VIEW_TDT_NUM].setEnabled(true); } tabs.setSelectedIndex(currentTab); contents.add(tabs); repaint(); setVisible(true); theData.finished = true; return null; }
theData = new HaploData();
theData = new HaploData(assocTest);
void readPedGenotypes(String[] f){ //input is a 3 element array with //inputOptions[0] = ped file //inputOptions[1] = info file (null if none) //inputOptions[2] = max comparison distance (don't compute d' if markers are greater than this dist apart) inputOptions = f; File pedFile = new File(inputOptions[0]); //pop open checkdata window //checkWindow = new JFrame(); try { if (pedFile.length() < 1){ throw new HaploViewException("Pedfile is empty or nonexistent: " + pedFile.getName()); } checkPanel = new CheckDataPanel(pedFile); checkPanel.setAlignmentX(Component.CENTER_ALIGNMENT); theData = new HaploData(); JTable table = checkPanel.getTable(); boolean[] markerResultArray = new boolean[table.getRowCount()]; for (int i = 0; i < table.getRowCount(); i++){ markerResultArray[i] = ((Boolean)table.getValueAt(i,7)).booleanValue(); } theData.linkageToChrom(markerResultArray,checkPanel.getPedFile()); processData(); }catch(IOException ioexec) { JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } catch(PedFileException pfe){ JOptionPane.showMessageDialog(this, pfe.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); }catch (HaploViewException hve){ JOptionPane.showMessageDialog(this, hve.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } }
doTDT = false;
assocTest = 0;
void readPhasedGenotypes(String[] f){ //input is a 3 element array with //inputOptions[0] = haps file //inputOptions[1] = info file (null if none) //inputOptions[2] = max comparison distance (don't compute d' if markers are greater than this dist apart) //these are not available for non ped files viewMenuItems[VIEW_CHECK_NUM].setEnabled(false); viewMenuItems[VIEW_TDT_NUM].setEnabled(false); checkPanel = null; doTDT = false; inputOptions = f; theData = new HaploData(); try{ theData.prepareHapsInput(new File(inputOptions[0])); processData(); }catch(IOException ioexec) { JOptionPane.showMessageDialog(this, ioexec.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); }catch(HaploViewException ex){ JOptionPane.showMessageDialog(this, ex.getMessage(), "File Error", JOptionPane.ERROR_MESSAGE); } }
if ( volumes == null ) { getDefaultVolume(); } vol = (Volume) volumes.get( volName );
PhotovaultSettings settings = PhotovaultSettings.getSettings(); PVDatabase db = settings.getCurrentDatabase(); vol = db.getVolume( volName );
public static Volume getVolume( String volName ) { Volume vol = null; // Initialize the volumes array and create default volume if it has not been done yet if ( volumes == null ) { getDefaultVolume(); } vol = (Volume) volumes.get( volName ); return vol; }
public TablePane(SQLTable m, PlayPen parentPP) { super(parentPP.getPlayPenContentPane()); setModel(m); setOpaque(true); setInsertionPoint(COLUMN_INDEX_NONE); dtl = new TablePaneDropListener(this); updateUI();
public TablePane(TablePane tp, PlayPenContentPane parent) { super(parent); this.model = tp.model; this.selectionListeners = new ArrayList<SelectionListener>(); this.dtl = new TablePaneDropListener(this); this.margin = (Insets) tp.margin.clone(); this.columnSelection = new ArrayList<Boolean>(tp.columnSelection); this.columnHighlight = new ArrayList<Color>(tp.columnHighlight); try { PlayPenComponentUI newUi = tp.getUI().getClass().newInstance(); newUi.installUI(this); setUI(newUi); } catch (InstantiationException e) { throw new RuntimeException("Woops, couldn't invoke no-args constructor of "+tp.getUI().getClass().getName()); } catch (IllegalAccessException e) { throw new RuntimeException("Woops, couldn't access no-args constructor of "+tp.getUI().getClass().getName()); } this.insertionPoint = tp.insertionPoint; this.draggingColumn = tp.draggingColumn; this.selected = false;
public TablePane(SQLTable m, PlayPen parentPP) { super(parentPP.getPlayPenContentPane()); setModel(m); setOpaque(true); setInsertionPoint(COLUMN_INDEX_NONE); //dt = new DropTarget(parentPP, new TablePaneDropListener(this)); dtl = new TablePaneDropListener(this); updateUI(); }
columnSelection = new ArrayList(numCols);
columnSelection = new ArrayList<Boolean>(numCols);
public void dbStructureChanged(SQLObjectEvent e) { if (e.getSource() == model.getColumnsFolder()) { int numCols = e.getChildren().length; columnSelection = new ArrayList(numCols); for (int i = 0; i < numCols; i++) { columnSelection.add(Boolean.FALSE); } columnHighlight = new ArrayList(numCols); for (int i = 0; i < numCols; i++) { columnHighlight.add(null); } firePropertyChange("model.children", null, null); //revalidate(); } }
columnHighlight = new ArrayList(numCols);
columnHighlight = new ArrayList<Color>(numCols);
public void dbStructureChanged(SQLObjectEvent e) { if (e.getSource() == model.getColumnsFolder()) { int numCols = e.getChildren().length; columnSelection = new ArrayList(numCols); for (int i = 0; i < numCols; i++) { columnSelection.add(Boolean.FALSE); } columnHighlight = new ArrayList(numCols); for (int i = 0; i < numCols; i++) { columnHighlight.add(null); } firePropertyChange("model.children", null, null); //revalidate(); } }
Iterator it = selectionListeners.iterator();
Iterator<SelectionListener> it = selectionListeners.iterator();
protected void fireSelectionEvent(SelectionEvent e) { if (logger.isDebugEnabled()) { logger.debug("Notifying "+selectionListeners.size() +" listeners of selection change"); } Iterator it = selectionListeners.iterator(); if (e.getType() == SelectionEvent.SELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemSelected(e); } } else if (e.getType() == SelectionEvent.DESELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemDeselected(e); } } else { throw new IllegalStateException("Unknown selection event type "+e.getType()); } }
((SelectionListener) it.next()).itemSelected(e);
it.next().itemSelected(e);
protected void fireSelectionEvent(SelectionEvent e) { if (logger.isDebugEnabled()) { logger.debug("Notifying "+selectionListeners.size() +" listeners of selection change"); } Iterator it = selectionListeners.iterator(); if (e.getType() == SelectionEvent.SELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemSelected(e); } } else if (e.getType() == SelectionEvent.DESELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemDeselected(e); } } else { throw new IllegalStateException("Unknown selection event type "+e.getType()); } }
((SelectionListener) it.next()).itemDeselected(e);
it.next().itemDeselected(e);
protected void fireSelectionEvent(SelectionEvent e) { if (logger.isDebugEnabled()) { logger.debug("Notifying "+selectionListeners.size() +" listeners of selection change"); } Iterator it = selectionListeners.iterator(); if (e.getType() == SelectionEvent.SELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemSelected(e); } } else if (e.getType() == SelectionEvent.DESELECTION_EVENT) { while (it.hasNext()) { ((SelectionListener) it.next()).itemDeselected(e); } } else { throw new IllegalStateException("Unknown selection event type "+e.getType()); } }
columnSelection = new ArrayList(m.getColumns().size());
columnSelection = new ArrayList<Boolean>(m.getColumns().size());
public void setModel(SQLTable m) { SQLTable old = model; if (m == null) { throw new IllegalArgumentException("model may not be null"); } else { model = m; } if (old != null) { try { ArchitectUtils.unlistenToHierarchy(this, old); } catch (ArchitectException e) { logger.error("Caught exception while unlistening to old model", e); } } try { columnSelection = new ArrayList(m.getColumns().size()); for (int i = 0; i < m.getColumns().size(); i++) { columnSelection.add(Boolean.FALSE); } columnHighlight = new ArrayList(m.getColumns().size()); for (int i = 0; i < m.getColumns().size(); i++) { columnHighlight.add(null); } } catch (ArchitectException e) { logger.error("Error getting children on new model", e); } try { ArchitectUtils.listenToHierarchy(this, model); } catch (ArchitectException e) { logger.error("Caught exception while listening to new model", e); } setName("TablePane: "+model.getShortDisplayName()); firePropertyChange("model", old, model); }
columnHighlight = new ArrayList(m.getColumns().size());
columnHighlight = new ArrayList<Color>(m.getColumns().size());
public void setModel(SQLTable m) { SQLTable old = model; if (m == null) { throw new IllegalArgumentException("model may not be null"); } else { model = m; } if (old != null) { try { ArchitectUtils.unlistenToHierarchy(this, old); } catch (ArchitectException e) { logger.error("Caught exception while unlistening to old model", e); } } try { columnSelection = new ArrayList(m.getColumns().size()); for (int i = 0; i < m.getColumns().size(); i++) { columnSelection.add(Boolean.FALSE); } columnHighlight = new ArrayList(m.getColumns().size()); for (int i = 0; i < m.getColumns().size(); i++) { columnHighlight.add(null); } } catch (ArchitectException e) { logger.error("Error getting children on new model", e); } try { ArchitectUtils.listenToHierarchy(this, model); } catch (ArchitectException e) { logger.error("Caught exception while listening to new model", e); } setName("TablePane: "+model.getShortDisplayName()); firePropertyChange("model", old, model); }
} else if (column == 17 ) { if (value == null) { formattedValue = "null"; } else if ( value instanceof Number ) { formattedValue = aldf.format(value); } else { formattedValue = value.toString(); }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String formattedValue = new String(); // System.out.println("row:"+row+" column:"+column); DecimalFormat pctFormat = new DecimalFormat("0%"); DecimalFormat aldf = new DecimalFormat("#,##0.0"); aldf.setMaximumFractionDigits(1); aldf.setMinimumFractionDigits(0); // map the column according to how the user has dragged // the columns in the view. column = table.convertColumnIndexToModel(column); if ( column < 5) { if (value == null) { formattedValue = "null"; } else { formattedValue = ((SQLObject)value).getName(); } }else if (column == 5) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); formattedValue =df.format(new Date((Long) value)); }else if (column == 9 || column == 11) { if (value == null) { formattedValue = "N/A"; } else { formattedValue = pctFormat.format(value); } } else if (column == 14 ) { if (value == null) { formattedValue = "null"; } else { formattedValue = aldf.format(value); } } else { if (value == null) { formattedValue = "null"; } else { formattedValue = value.toString(); } } return super.getTableCellRendererComponent(table,formattedValue,isSelected,hasFocus,row,column); }
FontRenderContext frc = c.getCurrentFontRederContext(); if (font == null || frc == null) { logger.error("getPreferredSize(): TablePane is missing font or fontRenderContext."); logger.error("getPreferredSize(): component="+c.getName()+"; font="+font+"; frc="+frc);
if (font == null) { logger.error("getPreferredSize(): TablePane is missing font.");
public Dimension getPreferredSize(JComponent jc) { TablePane c = (TablePane) jc; SQLTable table = c.getModel(); if (table == null) return null; int height = 0; int width = 0; try { Insets insets = c.getInsets(); java.util.List columnList = table.getColumns(); int cols = columnList.size(); Font font = c.getFont(); FontRenderContext frc = c.getCurrentFontRederContext(); if (font == null || frc == null) { logger.error("getPreferredSize(): TablePane is missing font or fontRenderContext."); logger.error("getPreferredSize(): component="+c.getName()+"; font="+font+"; frc="+frc); return null; } FontMetrics metrics = c.getFontMetrics(font); int fontHeight = metrics.getHeight(); height = insets.top + fontHeight + gap + c.getMargin().top + cols*fontHeight + boxLineThickness*2 + c.getMargin().bottom + insets.bottom; width = minimumWidth; logger.debug("starting width is: " + width); Iterator columnIt = table.getColumns().iterator(); while (columnIt.hasNext()) { String theColumn = columnIt.next().toString(); width = Math.max(width, (int) font.getStringBounds(theColumn, frc).getWidth()); logger.debug("new width is: " + width); } width += insets.left + c.getMargin().left + boxLineThickness*2 + c.getMargin().right + insets.right; } catch (ArchitectException e) { logger.warn("BasicTablePaneUI.getPreferredSize failed due to", e); width = 100; height = 100; } return new Dimension(width, height); }
width = Math.max(width, (int) font.getStringBounds(theColumn, frc).getWidth());
if (frc == null) { width = Math.max(width, metrics.stringWidth(theColumn)); } else { width = Math.max(width, (int) font.getStringBounds(theColumn, frc).getWidth()); }
public Dimension getPreferredSize(JComponent jc) { TablePane c = (TablePane) jc; SQLTable table = c.getModel(); if (table == null) return null; int height = 0; int width = 0; try { Insets insets = c.getInsets(); java.util.List columnList = table.getColumns(); int cols = columnList.size(); Font font = c.getFont(); FontRenderContext frc = c.getCurrentFontRederContext(); if (font == null || frc == null) { logger.error("getPreferredSize(): TablePane is missing font or fontRenderContext."); logger.error("getPreferredSize(): component="+c.getName()+"; font="+font+"; frc="+frc); return null; } FontMetrics metrics = c.getFontMetrics(font); int fontHeight = metrics.getHeight(); height = insets.top + fontHeight + gap + c.getMargin().top + cols*fontHeight + boxLineThickness*2 + c.getMargin().bottom + insets.bottom; width = minimumWidth; logger.debug("starting width is: " + width); Iterator columnIt = table.getColumns().iterator(); while (columnIt.hasNext()) { String theColumn = columnIt.next().toString(); width = Math.max(width, (int) font.getStringBounds(theColumn, frc).getWidth()); logger.debug("new width is: " + width); } width += insets.left + c.getMargin().left + boxLineThickness*2 + c.getMargin().right + insets.right; } catch (ArchitectException e) { logger.warn("BasicTablePaneUI.getPreferredSize failed due to", e); width = 100; height = 100; } return new Dimension(width, height); }
System.out.println("Marker " + (pos1+1) + " is monomorphic.");
public PairwiseLinkage computeDPrime(int pos1, int pos2){ compsDone++; int doublehet = 0; int[][] twoMarkerHaplos = new int[3][3]; for (int i = 0; i < twoMarkerHaplos.length; i++){ for (int j = 0; j < twoMarkerHaplos[i].length; j++){ twoMarkerHaplos[i][j] = 0; } } doublehet = 0; //get the alleles for the markers int m1a1 = 0; int m1a2 = 0; int m2a1 = 0; int m2a2 = 0; int m1H = 0; int m2H = 0; for (int i = 0; i < chromosomes.size(); i++){ byte a1 = ((Chromosome) chromosomes.elementAt(i)).getGenotype(pos1); byte a2 = ((Chromosome) chromosomes.elementAt(i)).getGenotype(pos2); if (m1a1 > 0){ if (m1a2 == 0 && !(a1 == 5) && !(a1 == 0) && a1 != m1a1) m1a2 = a1; } else if (!(a1 == 5) && !(a1 == 0)) m1a1=a1; if (m2a1 > 0){ if (m2a2 == 0 && !(a2 == 5) && !(a2 == 0) && a2 != m2a1) m2a2 = a2; } else if (!(a2 == 5) && !(a2 == 0)) m2a1=a2; if (a1 == 5) m1H++; if (a2 == 5) m2H++; } //check for non-polymorphic markers if (m1a2==0){ if (m1H==0){ System.out.println("Marker " + (pos1+1) + " is monomorphic.");//TODO Make this happier return null; } else { if (m1a1 == 1){ m1a2=2; } else { m1a2 = 1; } } } if (m2a2==0){ if (m2H==0){ return null; } else { if (m2a1 == 1){ m2a2=2; } else { m2a2 = 1; } } } int[] marker1num = new int[5]; int[] marker2num = new int[5]; marker1num[0]=0; marker1num[m1a1]=1; marker1num[m1a2]=2; marker2num[0]=0; marker2num[m2a1]=1; marker2num[m2a2]=2; //iterate through all chromosomes in dataset for (int i = 0; i < chromosomes.size(); i++){ //System.out.println(i + " " + pos1 + " " + pos2); //assign alleles for each of a pair of chromosomes at a marker to four variables byte a1 = ((Chromosome) chromosomes.elementAt(i)).getGenotype(pos1); byte a2 = ((Chromosome) chromosomes.elementAt(i)).getGenotype(pos2); byte b1 = ((Chromosome) chromosomes.elementAt(++i)).getGenotype(pos1); byte b2 = ((Chromosome) chromosomes.elementAt(i)).getGenotype(pos2); if (a1 == 0 || a2 == 0 || b1 == 0 || b2 == 0){ //skip missing data } else if ((a1 == 5 && a2 == 5) || (a1 == 5 && !(a2 == b2)) || (a2 == 5 && !(a1 == b1))) doublehet++; //find doublehets and resolved haplotypes else if (a1 == 5){ twoMarkerHaplos[1][marker2num[a2]]++; twoMarkerHaplos[2][marker2num[a2]]++; } else if (a2 == 5){ twoMarkerHaplos[marker1num[a1]][1]++; twoMarkerHaplos[marker1num[a1]][2]++; } else { twoMarkerHaplos[marker1num[a1]][marker2num[a2]]++; twoMarkerHaplos[marker1num[b1]][marker2num[b2]]++; } } //another monomorphic marker check int r1, r2, c1, c2; r1 = twoMarkerHaplos[1][1] + twoMarkerHaplos[1][2]; r2 = twoMarkerHaplos[2][1] + twoMarkerHaplos[2][2]; c1 = twoMarkerHaplos[1][1] + twoMarkerHaplos[2][1]; c2 = twoMarkerHaplos[1][2] + twoMarkerHaplos[2][2]; if ( (r1==0 || r2==0 || c1==0 || c2==0) && doublehet == 0){ return new PairwiseLinkage(1,0,0,0,0,new double[0]); } //compute D Prime for this pair of markers. //return is a tab delimited string of d', lod, r^2, CI(low), CI(high) this.realCompsDone++; int i,count; //int j,k,itmp; int low_i = 0; int high_i = 0; double loglike, oldloglike;// meand, mean2d, sd; double tmp;//g,h,m,tmp,r; double num, denom1, denom2, denom, dprime;//, real_dprime; double pA1, pB1, pA2, pB2, loglike1, loglike0, rsq; double tmpAA, tmpAB, tmpBA, tmpBB, dpr;// tmp2AA, tmp2AB, tmp2BA, tmp2BB; double total_prob, sum_prob; double lsurface[] = new double[105]; /* store arguments in externals and compute allele frequencies */ known[AA]=twoMarkerHaplos[1][1]; known[AB]=twoMarkerHaplos[1][2]; known[BA]=twoMarkerHaplos[2][1]; known[BB]=twoMarkerHaplos[2][2]; unknownDH=doublehet; total_chroms= (int)(known[AA]+known[AB]+known[BA]+known[BB]+(2*unknownDH)); pA1 = (known[AA]+known[AB]+unknownDH) / (double) total_chroms; pB1 = 1.0-pA1; pA2 = (known[AA]+known[BA]+unknownDH) / (double) total_chroms; pB2 = 1.0-pA2; const_prob = 0.1; /* set initial conditions */ if (const_prob < 0.00) { probHaps[AA]=pA1*pA2; probHaps[AB]=pA1*pB2; probHaps[BA]=pB1*pA2; probHaps[BB]=pB1*pB2; } else { probHaps[AA]=const_prob; probHaps[AB]=const_prob; probHaps[BA]=const_prob; probHaps[BB]=const_prob;; /* so that the first count step will produce an initial estimate without inferences (this should be closer and therefore speedier than assuming they are all at equal frequency) */ count_haps(0); estimate_p(); } /* now we have an initial reasonable guess at p we can start the EM - let the fun begin */ const_prob=0.0; count=1; loglike=-999999999.0; do { oldloglike=loglike; count_haps(count); loglike = known[AA]*log10(probHaps[AA]) + known[AB]*log10(probHaps[AB]) + known[BA]*log10(probHaps[BA]) + known[BB]*log10(probHaps[BB]) + (double)unknownDH*log10(probHaps[AA]*probHaps[BB] + probHaps[AB]*probHaps[BA]); if (Math.abs(loglike-oldloglike) < TOLERANCE) break; estimate_p(); count++; } while(count < 1000); /* in reality I've never seen it need more than 10 or so iterations to converge so this is really here just to keep it from running off into eternity */ loglike1 = known[AA]*log10(probHaps[AA]) + known[AB]*log10(probHaps[AB]) + known[BA]*log10(probHaps[BA]) + known[BB]*log10(probHaps[BB]) + (double)unknownDH*log10(probHaps[AA]*probHaps[BB] + probHaps[AB]*probHaps[BA]); loglike0 = known[AA]*log10(pA1*pA2) + known[AB]*log10(pA1*pB2) + known[BA]*log10(pB1*pA2) + known[BB]*log10(pB1*pB2) + (double)unknownDH*log10(2*pA1*pA2*pB1*pB2); num = probHaps[AA]*probHaps[BB] - probHaps[AB]*probHaps[BA]; if (num < 0) { /* flip matrix so we get the positive D' */ /* flip AA with AB and BA with BB */ tmp=probHaps[AA]; probHaps[AA]=probHaps[AB]; probHaps[AB]=tmp; tmp=probHaps[BB]; probHaps[BB]=probHaps[BA]; probHaps[BA]=tmp; /* flip frequency of second allele */ tmp=pA2; pA2=pB2; pB2=tmp; /* flip counts in the same fashion as p's */ tmp=numHaps[AA]; numHaps[AA]=numHaps[AB]; numHaps[AB]=tmp; tmp=numHaps[BB]; numHaps[BB]=numHaps[BA]; numHaps[BA]=tmp; /* num has now undergone a sign change */ num = probHaps[AA]*probHaps[BB] - probHaps[AB]*probHaps[BA]; /* flip known array for likelihood computation */ tmp=known[AA]; known[AA]=known[AB]; known[AB]=tmp; tmp=known[BB]; known[BB]=known[BA]; known[BA]=tmp; } denom1 = (probHaps[AA]+probHaps[BA])*(probHaps[BA]+probHaps[BB]); denom2 = (probHaps[AA]+probHaps[AB])*(probHaps[AB]+probHaps[BB]); if (denom1 < denom2) { denom = denom1; } else { denom = denom2; } dprime = num/denom; /* add computation of r^2 = (D^2)/p(1-p)q(1-q) */ rsq = num*num/(pA1*pB1*pA2*pB2); //real_dprime=dprime; for (i=0; i<=100; i++) { dpr = (double)i*0.01; tmpAA = dpr*denom + pA1*pA2; tmpAB = pA1-tmpAA; tmpBA = pA2-tmpAA; tmpBB = pB1-tmpBA; if (i==100) { /* one value will be 0 */ if (tmpAA < 1e-10) tmpAA=1e-10; if (tmpAB < 1e-10) tmpAB=1e-10; if (tmpBA < 1e-10) tmpBA=1e-10; if (tmpBB < 1e-10) tmpBB=1e-10; } lsurface[i] = known[AA]*log10(tmpAA) + known[AB]*log10(tmpAB) + known[BA]*log10(tmpBA) + known[BB]*log10(tmpBB) + (double)unknownDH*log10(tmpAA*tmpBB + tmpAB*tmpBA); } /* Confidence bounds #2 - used in Gabriel et al (2002) - translate into posterior dist of D' - assumes a flat prior dist. of D' - someday we may be able to make this even more clever by adjusting given the distribution of observed D' values for any given distance after some large scale studies are complete */ total_prob=sum_prob=0.0; for (i=0; i<=100; i++) { lsurface[i] -= loglike1; lsurface[i] = Math.pow(10.0,lsurface[i]); total_prob += lsurface[i]; } for (i=0; i<=100; i++) { sum_prob += lsurface[i]; if (sum_prob > 0.05*total_prob && sum_prob-lsurface[i] < 0.05*total_prob) { low_i = i-1; break; } } sum_prob=0.0; for (i=100; i>=0; i--) { sum_prob += lsurface[i]; if (sum_prob > 0.05*total_prob && sum_prob-lsurface[i] < 0.05*total_prob) { high_i = i+1; break; } } if (high_i > 100){ high_i = 100; } double[] freqarray = {probHaps[AA], probHaps[AB], probHaps[BB], probHaps[BA]}; return new PairwiseLinkage(roundDouble(dprime), roundDouble((loglike1-loglike0)), roundDouble(rsq), ((double)low_i/100.0), ((double)high_i/100.0), freqarray); }
void generateDPrimeTable(long maxdist){
void generateDPrimeTable(){
void generateDPrimeTable(long maxdist){ //calculating D prime requires the number of each possible 2 marker //haplotype in the dataset dPrimeTable = new PairwiseLinkage[Chromosome.getSize()][Chromosome.getSize()]; long negMaxdist = -1*maxdist; totalComps = (Chromosome.getSize()*(Chromosome.getSize()-1))/2; compsDone =0; //loop through all marker pairs for (int pos2 = 1; pos2 < dPrimeTable.length; pos2++){ for (int pos1 = 0; pos1 < pos2; pos1++){ //clear the array long sep = Chromosome.getMarker(pos2).getPosition() - Chromosome.getMarker(pos1).getPosition(); if (maxdist > 0){ if ((sep > maxdist || sep < negMaxdist)){ dPrimeTable[pos1][pos2] = null; continue; } } dPrimeTable[pos1][pos2] = computeDPrime(pos1, pos2); } } filteredDPrimeTable = getFilteredTable(); }
long negMaxdist = -1*maxdist;
void generateDPrimeTable(long maxdist){ //calculating D prime requires the number of each possible 2 marker //haplotype in the dataset dPrimeTable = new PairwiseLinkage[Chromosome.getSize()][Chromosome.getSize()]; long negMaxdist = -1*maxdist; totalComps = (Chromosome.getSize()*(Chromosome.getSize()-1))/2; compsDone =0; //loop through all marker pairs for (int pos2 = 1; pos2 < dPrimeTable.length; pos2++){ for (int pos1 = 0; pos1 < pos2; pos1++){ //clear the array long sep = Chromosome.getMarker(pos2).getPosition() - Chromosome.getMarker(pos1).getPosition(); if (maxdist > 0){ if ((sep > maxdist || sep < negMaxdist)){ dPrimeTable[pos1][pos2] = null; continue; } } dPrimeTable[pos1][pos2] = computeDPrime(pos1, pos2); } } filteredDPrimeTable = getFilteredTable(); }
long sep = Chromosome.getMarker(pos2).getPosition() - Chromosome.getMarker(pos1).getPosition(); if (maxdist > 0){ if ((sep > maxdist || sep < negMaxdist)){ dPrimeTable[pos1][pos2] = null; continue; } }
void generateDPrimeTable(long maxdist){ //calculating D prime requires the number of each possible 2 marker //haplotype in the dataset dPrimeTable = new PairwiseLinkage[Chromosome.getSize()][Chromosome.getSize()]; long negMaxdist = -1*maxdist; totalComps = (Chromosome.getSize()*(Chromosome.getSize()-1))/2; compsDone =0; //loop through all marker pairs for (int pos2 = 1; pos2 < dPrimeTable.length; pos2++){ for (int pos1 = 0; pos1 < pos2; pos1++){ //clear the array long sep = Chromosome.getMarker(pos2).getPosition() - Chromosome.getMarker(pos1).getPosition(); if (maxdist > 0){ if ((sep > maxdist || sep < negMaxdist)){ dPrimeTable[pos1][pos2] = null; continue; } } dPrimeTable[pos1][pos2] = computeDPrime(pos1, pos2); } } filteredDPrimeTable = getFilteredTable(); }
void prepareMarkerInput(File infile, long maxdist, String[][] hapmapGoodies) throws IOException, HaploViewException{
void prepareMarkerInput(File infile, long md, String[][] hapmapGoodies) throws IOException, HaploViewException{
void prepareMarkerInput(File infile, long maxdist, String[][] hapmapGoodies) throws IOException, HaploViewException{ //this method is called to gather data about the markers used. //It is assumed that the input file is two columns, the first being //the name and the second the absolute position. the maxdist is //used to determine beyond what distance comparisons will not be //made. if the infile param is null, loads up "dummy info" for //situation where no info file exists Vector names = new Vector(); Vector positions = new Vector(); try{ if (infile != null){ if (infile.length() < 1){ throw new HaploViewException("Info file is empty or does not exist: " + infile.getName()); } String currentLine; long negMaxdist = -1 * maxdist; long prevloc = -1000000000; //read the input file: BufferedReader in = new BufferedReader(new FileReader(infile)); int lineCount = 0; while ((currentLine = in.readLine()) != null){ StringTokenizer st = new StringTokenizer(currentLine); if (st.countTokens() > 1){ lineCount++; }else if (st.countTokens() == 1){ //complain if only one field found throw new HaploViewException("Info file format error on line "+lineCount+ ":\n Info file must be of format: <markername> <markerposition>"); }else{ //skip blank lines continue; } String name = st.nextToken(); String l = st.nextToken(); long loc; try{ loc = Long.parseLong(l); }catch (NumberFormatException nfe){ throw new HaploViewException("Info file format error on line "+lineCount+ ":\n\"" + l + "\" should be of type long." + "\n Info file must be of format: <markername> <markerposition>"); } if (loc < prevloc){ throw new HaploViewException("Info file out of order:\n"+ name); } prevloc = loc; names.add(name); positions.add(l); } if (lineCount > Chromosome.getSize()){ throw(new HaploViewException("Info file error:\nMarker number mismatch: too many\nmarkers in info file.")); } if (lineCount < Chromosome.getSize()){ throw(new HaploViewException("Info file error:\nMarker number mismatch: too few\nmarkers in info file.")); } infoKnown=true; } if (hapmapGoodies != null){ //we know some stuff from the hapmap so we'll add it here for (int x=0; x < hapmapGoodies.length; x++){ names.add(hapmapGoodies[x][0]); positions.add(hapmapGoodies[x][1]); } infoKnown = true; } }catch (HaploViewException e){ throw(e); }finally{ double numChroms = chromosomes.size(); Vector markerInfo = new Vector(); double[] numBadGenotypes = new double[Chromosome.getSize()]; percentBadGenotypes = new double[Chromosome.getSize()]; for (int i = 0; i < Chromosome.getSize(); i++){ //to compute maf, browse chrom list and count instances of each allele byte a1 = 0; double numa1 = 0; double numa2 = 0; for (int j = 0; j < chromosomes.size(); j++){ //if there is a data point for this marker on this chromosome byte thisAllele = ((Chromosome)chromosomes.elementAt(j)).getGenotype(i); if (!(thisAllele == 0)){ if (thisAllele == 5){ numa1+=0.5; numa2+=0.5; }else if (a1 == 0){ a1 = thisAllele; numa1++; }else if (thisAllele == a1){ numa1++; }else{ numa2++; } } else { numBadGenotypes[i]++; } } double maf = numa1/(numa2+numa1); if (maf > 0.5) maf = 1.0-maf; if (infoKnown){ markerInfo.add(new SNP((String)names.elementAt(i), Long.parseLong((String)positions.elementAt(i)), Math.rint(maf*100.0)/100.0)); }else{ markerInfo.add(new SNP("Marker " + String.valueOf(i+1), (i*4000), Math.rint(maf*100.0)/100.0)); } percentBadGenotypes[i] = numBadGenotypes[i]/numChroms; } Chromosome.markers = markerInfo.toArray(); } }
long negMaxdist = -1 * maxdist;
void prepareMarkerInput(File infile, long maxdist, String[][] hapmapGoodies) throws IOException, HaploViewException{ //this method is called to gather data about the markers used. //It is assumed that the input file is two columns, the first being //the name and the second the absolute position. the maxdist is //used to determine beyond what distance comparisons will not be //made. if the infile param is null, loads up "dummy info" for //situation where no info file exists Vector names = new Vector(); Vector positions = new Vector(); try{ if (infile != null){ if (infile.length() < 1){ throw new HaploViewException("Info file is empty or does not exist: " + infile.getName()); } String currentLine; long negMaxdist = -1 * maxdist; long prevloc = -1000000000; //read the input file: BufferedReader in = new BufferedReader(new FileReader(infile)); int lineCount = 0; while ((currentLine = in.readLine()) != null){ StringTokenizer st = new StringTokenizer(currentLine); if (st.countTokens() > 1){ lineCount++; }else if (st.countTokens() == 1){ //complain if only one field found throw new HaploViewException("Info file format error on line "+lineCount+ ":\n Info file must be of format: <markername> <markerposition>"); }else{ //skip blank lines continue; } String name = st.nextToken(); String l = st.nextToken(); long loc; try{ loc = Long.parseLong(l); }catch (NumberFormatException nfe){ throw new HaploViewException("Info file format error on line "+lineCount+ ":\n\"" + l + "\" should be of type long." + "\n Info file must be of format: <markername> <markerposition>"); } if (loc < prevloc){ throw new HaploViewException("Info file out of order:\n"+ name); } prevloc = loc; names.add(name); positions.add(l); } if (lineCount > Chromosome.getSize()){ throw(new HaploViewException("Info file error:\nMarker number mismatch: too many\nmarkers in info file.")); } if (lineCount < Chromosome.getSize()){ throw(new HaploViewException("Info file error:\nMarker number mismatch: too few\nmarkers in info file.")); } infoKnown=true; } if (hapmapGoodies != null){ //we know some stuff from the hapmap so we'll add it here for (int x=0; x < hapmapGoodies.length; x++){ names.add(hapmapGoodies[x][0]); positions.add(hapmapGoodies[x][1]); } infoKnown = true; } }catch (HaploViewException e){ throw(e); }finally{ double numChroms = chromosomes.size(); Vector markerInfo = new Vector(); double[] numBadGenotypes = new double[Chromosome.getSize()]; percentBadGenotypes = new double[Chromosome.getSize()]; for (int i = 0; i < Chromosome.getSize(); i++){ //to compute maf, browse chrom list and count instances of each allele byte a1 = 0; double numa1 = 0; double numa2 = 0; for (int j = 0; j < chromosomes.size(); j++){ //if there is a data point for this marker on this chromosome byte thisAllele = ((Chromosome)chromosomes.elementAt(j)).getGenotype(i); if (!(thisAllele == 0)){ if (thisAllele == 5){ numa1+=0.5; numa2+=0.5; }else if (a1 == 0){ a1 = thisAllele; numa1++; }else if (thisAllele == a1){ numa1++; }else{ numa2++; } } else { numBadGenotypes[i]++; } } double maf = numa1/(numa2+numa1); if (maf > 0.5) maf = 1.0-maf; if (infoKnown){ markerInfo.add(new SNP((String)names.elementAt(i), Long.parseLong((String)positions.elementAt(i)), Math.rint(maf*100.0)/100.0)); }else{ markerInfo.add(new SNP("Marker " + String.valueOf(i+1), (i*4000), Math.rint(maf*100.0)/100.0)); } percentBadGenotypes[i] = numBadGenotypes[i]/numChroms; } Chromosome.markers = markerInfo.toArray(); } }
if (showWM && worldmapRect.contains(clickX,clickY)){
if (showWM && wmInteriorRect.contains(clickX,clickY)){
public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { int clickX = e.getX(); int clickY = e.getY(); if (showWM && worldmapRect.contains(clickX,clickY)){ //convert a click on the worldmap to a point on the big picture int bigClickX = (((clickX - getVisibleRect().x) * chartSize.width) / worldmap.getWidth())-getVisibleRect().width/2; int bigClickY = (((clickY - getVisibleRect().y - (getVisibleRect().height-worldmap.getHeight())) * chartSize.height) / worldmap.getHeight()) - getVisibleRect().height/2 + infoHeight; //if the clicks are near the edges, correct values if (bigClickX > chartSize.width - getVisibleRect().width){ bigClickX = chartSize.width - getVisibleRect().width; } if (bigClickX < 0){ bigClickX = 0; } if (bigClickY > chartSize.height - getVisibleRect().height + infoHeight){ bigClickY = chartSize.height - getVisibleRect().height + infoHeight; } if (bigClickY < 0){ bigClickY = 0; } ((JViewport)getParent()).setViewPosition(new Point(bigClickX,bigClickY)); }else{ Rectangle blockselector = new Rectangle(clickXShift-boxRadius,clickYShift - boxRadius, (Chromosome.getFilteredSize()*boxSize), boxSize); if(blockselector.contains(clickX,clickY)){ int whichMarker = (int)(0.5 + (double)((clickX - clickXShift))/boxSize); if (theData.isInBlock[whichMarker]){ theData.removeFromBlock(whichMarker); refresh(0); } else if (whichMarker > 0 && whichMarker < Chromosome.realIndex.length){ theData.addMarkerIntoSurroundingBlock(whichMarker); } } } } }
int bigClickX = (((clickX - getVisibleRect().x) * chartSize.width) / worldmap.getWidth())-getVisibleRect().width/2;
int bigClickX = (((clickX - getVisibleRect().x - (worldmap.getWidth()-wmInteriorRect.width)/2) * chartSize.width) / wmInteriorRect.width)-getVisibleRect().width/2;
public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { int clickX = e.getX(); int clickY = e.getY(); if (showWM && worldmapRect.contains(clickX,clickY)){ //convert a click on the worldmap to a point on the big picture int bigClickX = (((clickX - getVisibleRect().x) * chartSize.width) / worldmap.getWidth())-getVisibleRect().width/2; int bigClickY = (((clickY - getVisibleRect().y - (getVisibleRect().height-worldmap.getHeight())) * chartSize.height) / worldmap.getHeight()) - getVisibleRect().height/2 + infoHeight; //if the clicks are near the edges, correct values if (bigClickX > chartSize.width - getVisibleRect().width){ bigClickX = chartSize.width - getVisibleRect().width; } if (bigClickX < 0){ bigClickX = 0; } if (bigClickY > chartSize.height - getVisibleRect().height + infoHeight){ bigClickY = chartSize.height - getVisibleRect().height + infoHeight; } if (bigClickY < 0){ bigClickY = 0; } ((JViewport)getParent()).setViewPosition(new Point(bigClickX,bigClickY)); }else{ Rectangle blockselector = new Rectangle(clickXShift-boxRadius,clickYShift - boxRadius, (Chromosome.getFilteredSize()*boxSize), boxSize); if(blockselector.contains(clickX,clickY)){ int whichMarker = (int)(0.5 + (double)((clickX - clickXShift))/boxSize); if (theData.isInBlock[whichMarker]){ theData.removeFromBlock(whichMarker); refresh(0); } else if (whichMarker > 0 && whichMarker < Chromosome.realIndex.length){ theData.addMarkerIntoSurroundingBlock(whichMarker); } } } } }
chartSize.height) / worldmap.getHeight()) -
chartSize.height) / wmInteriorRect.height) -
public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { int clickX = e.getX(); int clickY = e.getY(); if (showWM && worldmapRect.contains(clickX,clickY)){ //convert a click on the worldmap to a point on the big picture int bigClickX = (((clickX - getVisibleRect().x) * chartSize.width) / worldmap.getWidth())-getVisibleRect().width/2; int bigClickY = (((clickY - getVisibleRect().y - (getVisibleRect().height-worldmap.getHeight())) * chartSize.height) / worldmap.getHeight()) - getVisibleRect().height/2 + infoHeight; //if the clicks are near the edges, correct values if (bigClickX > chartSize.width - getVisibleRect().width){ bigClickX = chartSize.width - getVisibleRect().width; } if (bigClickX < 0){ bigClickX = 0; } if (bigClickY > chartSize.height - getVisibleRect().height + infoHeight){ bigClickY = chartSize.height - getVisibleRect().height + infoHeight; } if (bigClickY < 0){ bigClickY = 0; } ((JViewport)getParent()).setViewPosition(new Point(bigClickX,bigClickY)); }else{ Rectangle blockselector = new Rectangle(clickXShift-boxRadius,clickYShift - boxRadius, (Chromosome.getFilteredSize()*boxSize), boxSize); if(blockselector.contains(clickX,clickY)){ int whichMarker = (int)(0.5 + (double)((clickX - clickXShift))/boxSize); if (theData.isInBlock[whichMarker]){ theData.removeFromBlock(whichMarker); refresh(0); } else if (whichMarker > 0 && whichMarker < Chromosome.realIndex.length){ theData.addMarkerIntoSurroundingBlock(whichMarker); } } } } }
int width = e.getX() - worldmapRect.x;
int width = e.getX() - wmInteriorRect.x;
public void mouseDragged(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { //conveniently, we can tell what do do with the drag event //based on what the cursor is if (getCursor() == Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)){ int width = e.getX() - worldmapRect.x; double ratio = (double)width/(double)worldmap.getWidth(); int height = (int)(ratio*worldmap.getHeight()); resizeWMRect = new Rectangle(worldmapRect.x+1, worldmapRect.y + worldmapRect.height - height, width, height-1); resizeRectExists = true; repaint(); }else if (getCursor() == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)){ int xcorner,width; if (e.getX() < blockStartX){ //we're dragging right to left, so flip it. xcorner = e.getX() - clickXShift + left; width = blockStartX - e.getX(); }else{ xcorner = blockStartX - clickXShift + left; width = e.getX() - blockStartX; } blockRect = new Rectangle(xcorner, top - boxRadius/2 - TEXT_GAP, width,boxRadius); blockRectExists=true; repaint(); } } }
resizeWMRect = new Rectangle(worldmapRect.x+1, worldmapRect.y + worldmapRect.height - height,
resizeWMRect = new Rectangle(wmInteriorRect.x+1, wmInteriorRect.y + wmInteriorRect.height - height,
public void mouseDragged(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { //conveniently, we can tell what do do with the drag event //based on what the cursor is if (getCursor() == Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)){ int width = e.getX() - worldmapRect.x; double ratio = (double)width/(double)worldmap.getWidth(); int height = (int)(ratio*worldmap.getHeight()); resizeWMRect = new Rectangle(worldmapRect.x+1, worldmapRect.y + worldmapRect.height - height, width, height-1); resizeRectExists = true; repaint(); }else if (getCursor() == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)){ int xcorner,width; if (e.getX() < blockStartX){ //we're dragging right to left, so flip it. xcorner = e.getX() - clickXShift + left; width = blockStartX - e.getX(); }else{ xcorner = blockStartX - clickXShift + left; width = e.getX() - blockStartX; } blockRect = new Rectangle(xcorner, top - boxRadius/2 - TEXT_GAP, width,boxRadius); blockRectExists=true; repaint(); } } }
!(worldmapRect.contains(clickX,clickY))){
!(wmInteriorRect.contains(clickX,clickY))){
public void mousePressed (MouseEvent e) { Rectangle blockselector = new Rectangle(clickXShift-boxRadius,clickYShift - boxRadius, (Chromosome.getFilteredSize()*boxSize), boxSize); //if users right clicks & holds, pop up the info if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK){ Graphics g = getGraphics(); g.setFont(boxFont); FontMetrics metrics = g.getFontMetrics(); PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; final int clickX = e.getX(); final int clickY = e.getY(); double dboxX = (double)(clickX - clickXShift - (clickY-clickYShift))/boxSize; double dboxY = (double)(clickX - clickXShift + (clickY-clickYShift))/boxSize; final int boxX, boxY; if (dboxX < 0){ boxX = (int)(dboxX - 0.5); } else{ boxX = (int)(dboxX + 0.5); } if (dboxY < 0){ boxY = (int)(dboxY - 0.5); }else{ boxY = (int)(dboxY + 0.5); } if ((boxX >= lowX && boxX <= highX) && (boxY > boxX && boxY < highY) && !(worldmapRect.contains(clickX,clickY))){ if (dPrimeTable[boxX][boxY] != null){ displayStrings = new String[5]; if (theData.infoKnown){ displayStrings[0] = new String ("(" +Chromosome.getFilteredMarker(boxX).getName() + ", " + Chromosome.getFilteredMarker(boxY).getName() + ")"); }else{ displayStrings[0] = new String("(" + (Chromosome.realIndex[boxX]+1) + ", " + (Chromosome.realIndex[boxY]+1) + ")"); } displayStrings[1] = new String ("D': " + dPrimeTable[boxX][boxY].getDPrime()); displayStrings[2] = new String ("LOD: " + dPrimeTable[boxX][boxY].getLOD()); displayStrings[3] = new String ("r^2: " + dPrimeTable[boxX][boxY].getRSquared()); displayStrings[4] = new String ("D' conf. bounds: " + dPrimeTable[boxX][boxY].getConfidenceLow() + "-" + dPrimeTable[boxX][boxY].getConfidenceHigh()); popupExists = true; } } else if (blockselector.contains(clickX, clickY)){ int marker = (int)(0.5 + (double)((clickX - clickXShift))/boxSize); displayStrings = new String[2]; if (theData.infoKnown){ displayStrings[0] = new String (Chromosome.getFilteredMarker(marker).getName()); }else{ displayStrings[0] = new String("Marker " + (Chromosome.realIndex[marker]+1)); } displayStrings[1] = new String ("MAF: " + Chromosome.getFilteredMarker(marker).getMAF()); popupExists = true; } if (popupExists){ int strlen = 0; for (int x = 0; x < displayStrings.length; x++){ if (strlen < metrics.stringWidth(displayStrings[x])){ strlen = metrics.stringWidth(displayStrings[x]); } } //edge shifts prevent window from popping up partially offscreen int visRightBound = (int)(getVisibleRect().getWidth() + getVisibleRect().getX()); int visBotBound = (int)(getVisibleRect().getHeight() + getVisibleRect().getY()); int rightEdgeShift = 0; if (clickX + strlen + popupLeftMargin +5 > visRightBound){ rightEdgeShift = clickX + strlen + popupLeftMargin + 10 - visRightBound; } int botEdgeShift = 0; if (clickY + 5*metrics.getHeight()+10 > visBotBound){ botEdgeShift = clickY + 5*metrics.getHeight()+15 - visBotBound; } int smallDataVertSlop = 0; if (getPreferredSize().getWidth() < getVisibleRect().width && theData.infoKnown){ smallDataVertSlop = (int)(getVisibleRect().height - getPreferredSize().getHeight())/2; } popupDrawRect = new Rectangle(clickX-rightEdgeShift, clickY-botEdgeShift+smallDataVertSlop, strlen+popupLeftMargin+5, displayStrings.length*metrics.getHeight()+10); repaint(); } }else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK){ int x = e.getX(); int y = e.getY(); if (blockselector.contains(x,y)){ setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); blockStartX = x; } } }
ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight());
wmInteriorRect = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight());
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
ir.width,
wmInteriorRect.width,
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2,
wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-wmInteriorRect.width)/2,
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
(worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2);
(worldmap.getWidth()-wmInteriorRect.width)/2, (worldmap.getHeight() -wmInteriorRect.height)/2);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight());
wmInteriorRect.x = visRect.x + (worldmap.getWidth() - wmInteriorRect.width); wmInteriorRect.y = visRect.y+visRect.height-worldmap.getHeight() + (worldmap.getHeight() - wmInteriorRect.height);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height;
double hRatio = wmInteriorRect.getWidth()/pref.getWidth(); double vRatio = wmInteriorRect.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-wmInteriorRect.width; int vBump = worldmap.getHeight()-wmInteriorRect.height;
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(boldMarkerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, top, xx, top + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (boxColor == Color.darkGray){ g2.setColor(Color.white); } if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < displayStrings.length; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
JMenu imageMenu = new JMenu( "Image" ); imageMenu.setMnemonic(KeyEvent.VK_I); menuBar.add( imageMenu ); imageMenu.add( new JMenuItem( viewPane.getEditSelectionPropsAction() ) ); imageMenu.add( new JMenuItem( viewPane.getShowSelectedPhotoAction() ) ); imageMenu.add( new JMenuItem( viewPane.getRotateCWActionAction() ) ); imageMenu.add( new JMenuItem( viewPane.getRotateCCWActionAction() ) ); imageMenu.add( new JMenuItem( viewPane.getRotate180degActionAction() ) );
protected void createUI() { setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); tabPane = new JTabbedPane(); queryPane = new QueryPane(); treePane = new PhotoFolderTree(); tabPane.addTab( "Query", queryPane ); tabPane.addTab( "Folders", treePane ); // viewPane = new TableCollectionView(); viewPane = new PhotoCollectionThumbView(); viewPane.setCollection( queryPane.getResultCollection() ); // Set listeners to both query and folder tree panes /* If an actionEvent comes from queryPane & the viewed folder is no the query resouts, swich to it (the result folder will be nodified of changes to quert parameters directly */ queryPane.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { if ( viewPane.getCollection() != queryPane.getResultCollection() ) { viewPane.setCollection( queryPane.getResultCollection() ); } } } ); /* If the selected folder is changed in treePane, switch to that immediately */ treePane.addPhotoFolderTreeListener( new PhotoFolderTreeListener() { public void photoFolderTreeSelectionChanged( PhotoFolderTreeEvent e ) { PhotoFolder f = e.getSelected(); if ( f != null ) { viewPane.setCollection( f ); } } } ); // Create the split pane to display both of these components JScrollPane viewScroll = new JScrollPane( viewPane ); viewScroll.setPreferredSize( new Dimension( 650, 400 ) ); JSplitPane split = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT, tabPane, viewScroll ); Container cp = getContentPane(); cp.setLayout( new BorderLayout() ); cp.add( split, BorderLayout.CENTER ); // Create the menu bar & menus JMenuBar menuBar = new JMenuBar(); setJMenuBar( menuBar ); JMenu fileMenu = new JMenu( "File" ); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add( fileMenu ); JMenuItem newWindowItem = new JMenuItem( "New window", KeyEvent.VK_N ); newWindowItem.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { BrowserWindow br = new BrowserWindow(); // br.setVisible( true ); } }); fileMenu.add( newWindowItem ); JMenuItem importItem = new JMenuItem( "Import image...", KeyEvent.VK_I ); importItem.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { importFile(); } }); fileMenu.add( importItem );// JMenuItem exportItem = new JMenuItem( "Export image...", KeyEvent.VK_E );// exportItem.addActionListener( new ActionListener() {// public void actionPerformed( ActionEvent e ) {// exportSelected();// }// }); JMenuItem exportItem = new JMenuItem( viewPane.getExportSelectedAction() ); fileMenu.add( exportItem ); JMenuItem exitItem = new JMenuItem( "Exit", KeyEvent.VK_X ); exitItem.addActionListener( new ActionListener() { public void actionPerformed( ActionEvent e ) { System.exit( 0 ); } }); fileMenu.add( exitItem ); pack(); setVisible( true ); }
Tag tag = (Tag) type.newInstance(); return TagScript.newInstance(tag);
return TagScript.newInstance(type);
public TagScript createTagScript(String name, Attributes attributes) throws Exception { Class type = (Class) tags.get(name); if ( type != null ) { Tag tag = (Tag) type.newInstance(); return TagScript.newInstance(tag); } return null; }
JButton okButton = new JButton(compareDMPanel.getStartCompareAction());
JDefaultButton okButton = new JDefaultButton(compareDMPanel.getStartCompareAction());
public void actionPerformed(ActionEvent e) { // This can not easily be replaced with ArchitectPanelBuilder // because the current CompareDMPanel is not an ArchitectPanel // (and has no intention of becoming one, without some work). final JDialog d = new JDialog(ArchitectFrame.getMainInstance(), "Compare Data Models"); JPanel cp = new JPanel(new BorderLayout(12,12)); cp.setBorder(BorderFactory.createEmptyBorder(12,12,12,12)); final CompareDMPanel compareDMPanel = new CompareDMPanel(architectFrame.getProject()); cp.add(compareDMPanel, BorderLayout.CENTER);// JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JPanel buttonPanel = compareDMPanel.getButtonPanel(); JButton okButton = new JButton(compareDMPanel.getStartCompareAction()); buttonPanel.add(okButton); JButton cancelButton = new JButton(new CommonCloseAction(d)); buttonPanel.add(cancelButton); cp.add(buttonPanel, BorderLayout.SOUTH); ArchitectPanelBuilder.makeJDialogCancellable(d, cancelButton.getAction()); d.getRootPane().setDefaultButton(okButton); d.setContentPane(cp); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); }
boolean resultFound = false;
public void parseMoreResults(String wga) throws PlinkException { File moreResultsFile = new File(wga); results = hv.getPlinkData(); columns = hv.getPlinkColumns(); Vector newColumns = new Vector(); Vector ignoredMarkers = new Vector(); boolean addColumns = false; try{ if (moreResultsFile.length() < 1){ throw new PlinkException("plink file is empty or nonexistent."); } BufferedReader moreResultsReader = new BufferedReader(new FileReader(moreResultsFile)); int numColumns = 0; int markerColumn = -1; int chromColumn = -1; String headerLine = moreResultsReader.readLine(); StringTokenizer headerSt = new StringTokenizer(headerLine); while (headerSt.hasMoreTokens()){ String column = new String(headerSt.nextToken()); if (column.equals("SNP")){ if (markerColumn != -1){ throw new PlinkException("Results file contains more then one SNP column."); } markerColumn = numColumns; numColumns++; }else if (column.equals("CHR")){ chromColumn = numColumns; numColumns++; }else{ if(columns.contains(column)){ String dupColumn = column + "*"; JOptionPane.showMessageDialog(hv, column + " already appears in the dataset.\n" + "Duplicates are marked as " + dupColumn, "Duplicate value", JOptionPane.ERROR_MESSAGE); newColumns.add(dupColumn); }else{ newColumns.add(column); } numColumns++; } } if (markerColumn == -1){ throw new PlinkException("Results file must contain a SNP column."); } String wgaLine; int lineNumber = 0; while((wgaLine = moreResultsReader.readLine())!=null){ if (wgaLine.length() == 0){ //skip blank lines continue; } int tokenNumber = 0; StringTokenizer tokenizer = new StringTokenizer(wgaLine); String marker = null; String chrom = null; Vector values = new Vector(); while(tokenizer.hasMoreTokens()){ if (tokenNumber == markerColumn){ marker = new String(tokenizer.nextToken()); }else if(tokenNumber == chromColumn){ chrom = new String(tokenizer.nextToken()); //TODO: mess with this nonsense. if(chrom.equals("23")){ chrom = "X"; } } else{ String value = tokenizer.nextToken(); values.add(value); } tokenNumber++; } if (tokenNumber != numColumns){ throw new PlinkException("Inconsistent column number on line " + (lineNumber+1)); } AssociationResult currentResult; boolean resultFound = false; for (int i = 0; i < results.size(); i++){ currentResult = (AssociationResult)results.get(i); if (currentResult.getMarker().getMarkerID().equals(marker)){ resultFound = true; currentResult.addValues(values); break; } } if (resultFound){ addColumns = true; }else{ ignoredMarkers.add(marker); } lineNumber++; } }catch(IOException ioe){ throw new PlinkException("File error."); } if (ignoredMarkers.size() != 0){ IgnoredMarkersDialog imd = new IgnoredMarkersDialog(hv,"Ignored Markers",ignoredMarkers); imd.pack(); imd.setVisible(true); } if (addColumns){ for (int i = 0; i < newColumns.size(); i++){ columns.add(newColumns.get(i)); } } hv.setPlinkData(results,columns); }
for (int i = 0; i < results.size(); i++){ currentResult = (AssociationResult)results.get(i); if (currentResult.getMarker().getMarkerID().equals(marker)){ resultFound = true; currentResult.addValues(values); break; } } if (resultFound){
if (resultsHash.containsKey(marker)){
public void parseMoreResults(String wga) throws PlinkException { File moreResultsFile = new File(wga); results = hv.getPlinkData(); columns = hv.getPlinkColumns(); Vector newColumns = new Vector(); Vector ignoredMarkers = new Vector(); boolean addColumns = false; try{ if (moreResultsFile.length() < 1){ throw new PlinkException("plink file is empty or nonexistent."); } BufferedReader moreResultsReader = new BufferedReader(new FileReader(moreResultsFile)); int numColumns = 0; int markerColumn = -1; int chromColumn = -1; String headerLine = moreResultsReader.readLine(); StringTokenizer headerSt = new StringTokenizer(headerLine); while (headerSt.hasMoreTokens()){ String column = new String(headerSt.nextToken()); if (column.equals("SNP")){ if (markerColumn != -1){ throw new PlinkException("Results file contains more then one SNP column."); } markerColumn = numColumns; numColumns++; }else if (column.equals("CHR")){ chromColumn = numColumns; numColumns++; }else{ if(columns.contains(column)){ String dupColumn = column + "*"; JOptionPane.showMessageDialog(hv, column + " already appears in the dataset.\n" + "Duplicates are marked as " + dupColumn, "Duplicate value", JOptionPane.ERROR_MESSAGE); newColumns.add(dupColumn); }else{ newColumns.add(column); } numColumns++; } } if (markerColumn == -1){ throw new PlinkException("Results file must contain a SNP column."); } String wgaLine; int lineNumber = 0; while((wgaLine = moreResultsReader.readLine())!=null){ if (wgaLine.length() == 0){ //skip blank lines continue; } int tokenNumber = 0; StringTokenizer tokenizer = new StringTokenizer(wgaLine); String marker = null; String chrom = null; Vector values = new Vector(); while(tokenizer.hasMoreTokens()){ if (tokenNumber == markerColumn){ marker = new String(tokenizer.nextToken()); }else if(tokenNumber == chromColumn){ chrom = new String(tokenizer.nextToken()); //TODO: mess with this nonsense. if(chrom.equals("23")){ chrom = "X"; } } else{ String value = tokenizer.nextToken(); values.add(value); } tokenNumber++; } if (tokenNumber != numColumns){ throw new PlinkException("Inconsistent column number on line " + (lineNumber+1)); } AssociationResult currentResult; boolean resultFound = false; for (int i = 0; i < results.size(); i++){ currentResult = (AssociationResult)results.get(i); if (currentResult.getMarker().getMarkerID().equals(marker)){ resultFound = true; currentResult.addValues(values); break; } } if (resultFound){ addColumns = true; }else{ ignoredMarkers.add(marker); } lineNumber++; } }catch(IOException ioe){ throw new PlinkException("File error."); } if (ignoredMarkers.size() != 0){ IgnoredMarkersDialog imd = new IgnoredMarkersDialog(hv,"Ignored Markers",ignoredMarkers); imd.pack(); imd.setVisible(true); } if (addColumns){ for (int i = 0; i < newColumns.size(); i++){ columns.add(newColumns.get(i)); } } hv.setPlinkData(results,columns); }
currentResult = (AssociationResult)results.get(((Integer)resultsHash.get(marker)).intValue()); currentResult.addValues(values);
public void parseMoreResults(String wga) throws PlinkException { File moreResultsFile = new File(wga); results = hv.getPlinkData(); columns = hv.getPlinkColumns(); Vector newColumns = new Vector(); Vector ignoredMarkers = new Vector(); boolean addColumns = false; try{ if (moreResultsFile.length() < 1){ throw new PlinkException("plink file is empty or nonexistent."); } BufferedReader moreResultsReader = new BufferedReader(new FileReader(moreResultsFile)); int numColumns = 0; int markerColumn = -1; int chromColumn = -1; String headerLine = moreResultsReader.readLine(); StringTokenizer headerSt = new StringTokenizer(headerLine); while (headerSt.hasMoreTokens()){ String column = new String(headerSt.nextToken()); if (column.equals("SNP")){ if (markerColumn != -1){ throw new PlinkException("Results file contains more then one SNP column."); } markerColumn = numColumns; numColumns++; }else if (column.equals("CHR")){ chromColumn = numColumns; numColumns++; }else{ if(columns.contains(column)){ String dupColumn = column + "*"; JOptionPane.showMessageDialog(hv, column + " already appears in the dataset.\n" + "Duplicates are marked as " + dupColumn, "Duplicate value", JOptionPane.ERROR_MESSAGE); newColumns.add(dupColumn); }else{ newColumns.add(column); } numColumns++; } } if (markerColumn == -1){ throw new PlinkException("Results file must contain a SNP column."); } String wgaLine; int lineNumber = 0; while((wgaLine = moreResultsReader.readLine())!=null){ if (wgaLine.length() == 0){ //skip blank lines continue; } int tokenNumber = 0; StringTokenizer tokenizer = new StringTokenizer(wgaLine); String marker = null; String chrom = null; Vector values = new Vector(); while(tokenizer.hasMoreTokens()){ if (tokenNumber == markerColumn){ marker = new String(tokenizer.nextToken()); }else if(tokenNumber == chromColumn){ chrom = new String(tokenizer.nextToken()); //TODO: mess with this nonsense. if(chrom.equals("23")){ chrom = "X"; } } else{ String value = tokenizer.nextToken(); values.add(value); } tokenNumber++; } if (tokenNumber != numColumns){ throw new PlinkException("Inconsistent column number on line " + (lineNumber+1)); } AssociationResult currentResult; boolean resultFound = false; for (int i = 0; i < results.size(); i++){ currentResult = (AssociationResult)results.get(i); if (currentResult.getMarker().getMarkerID().equals(marker)){ resultFound = true; currentResult.addValues(values); break; } } if (resultFound){ addColumns = true; }else{ ignoredMarkers.add(marker); } lineNumber++; } }catch(IOException ioe){ throw new PlinkException("File error."); } if (ignoredMarkers.size() != 0){ IgnoredMarkersDialog imd = new IgnoredMarkersDialog(hv,"Ignored Markers",ignoredMarkers); imd.pack(); imd.setVisible(true); } if (addColumns){ for (int i = 0; i < newColumns.size(); i++){ columns.add(newColumns.get(i)); } } hv.setPlinkData(results,columns); }
if (type == 1){
if (type == ASSOC_TRIO){
public double getChiSq(int type) { if(!this.chiSet){ if (type == 1){ this.chiSqVal = Math.pow( (this.counts[0][0] - this.counts[0][1]),2) / (this.counts[0][0] + this.counts[0][1]); }else{ int N = counts[0][0] + counts[0][1] + counts[1][0] + counts[1][1]; for (int i = 0; i < 2; i++){ for (int j = 0; j < 2; j++){ double nij = ((double)(counts[i][0] + counts[i][1])*(counts[0][j] + counts[1][j]))/N; this.chiSqVal += Math.pow( (this.counts[i][j] - nij), 2) / nij; } } } this.chiSqVal = Math.rint(this.chiSqVal*1000.0)/1000.0; this.chiSet = true; } return this.chiSqVal; }
if (type != 1){
if (type != ASSOC_TRIO){
public String getOverTransmittedAllele(int type) { String[] alleleCodes = new String[5]; alleleCodes[0] = "X"; alleleCodes[1] = "A"; alleleCodes[2] = "C"; alleleCodes[3] = "G"; alleleCodes[4] = "T"; String retStr; if (this.counts[0][0] > this.counts[0][1]){ retStr = alleleCodes[allele1]; }else if (this.counts[0][0] == this.counts[0][1]){ retStr = "-"; }else{ retStr = alleleCodes[allele2]; } if (type != 1){ if (this.counts[1][0] > this.counts[1][1]){ retStr += (", " + alleleCodes[allele1]); }else if (this.counts[1][0] == this.counts[1][1]){ retStr += ", -"; }else{ retStr += (", " + alleleCodes[allele2]); } } return retStr; }
if (type == 1){
if (type == ASSOC_TRIO){
public String getTURatio(int type) { if (type == 1){ if (this.counts[0][0] > this.counts[0][1]){ return this.counts[0][0] + ":" + this.counts[0][1]; }else{ return this.counts[0][1] + ":" + this.counts[0][0]; } }else{ if (this.counts[0][0] > this.counts[0][1]){ if (this.counts[1][0] > this.counts[1][1]){ return this.counts[0][0] + ":" + this.counts[0][1] + ", " + this.counts[1][0] + ":" + this.counts[1][1]; }else{ return this.counts[0][0] + ":" + this.counts[0][1] + "," + this.counts[1][1] + ":" + this.counts[1][0]; } }else{ if (this.counts[1][0] > this.counts[1][1]){ return this.counts[0][1] + ":" + this.counts[0][0] + ", " + this.counts[1][0] + ":" + this.counts[1][1]; }else{ return this.counts[0][1] + ":" + this.counts[0][0] + "," + this.counts[1][1] + ":" + this.counts[1][0]; } } } }
monitorableProgress = 0;
public void dropConflicting() throws SQLException { if (conflicts == null) { throw new IllegalStateException("You have to call findConflicting() before dropConflicting()"); } dropConflictingStarted = true; Iterator it = conflicts.iterator(); Statement stmt = null; try { stmt = con.createStatement(); Set alreadyDropped = new HashSet(); while (it.hasNext()) { Conflict c = (Conflict) it.next(); monitorableProgress++; dropConflict(c, stmt, alreadyDropped); } } finally { dropConflictingFinished = true; if (stmt != null) stmt.close(); } }
ddlStatements.add(new DDLStatement(sqlObject, type, ddl.toString()));
String cat = getTargetCatalog(); if (cat != null) { cat = toIdentifier(cat); } String sch = getTargetSchema(); if (sch != null) { sch = toIdentifier(sch); } ddlStatements.add(new DDLStatement(sqlObject, type, ddl.toString(), cat, sch));
public final void endStatement(DDLStatement.StatementType type, SQLObject sqlObject) { ddlStatements.add(new DDLStatement(sqlObject, type, ddl.toString())); ddl = new StringBuffer(500); }
if (caller.dPrimeDisplay != null){ caller.dPrimeDisplay.setVisible(false); }
public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command==RAW_DATA){ load(PED); }else if (command == PHASED_DATA){ load(HAPS); }else if (command == BROWSE_GENO){ browse(GENO); }else if (command == BROWSE_INFO){ browse(INFO); }else if (command == HAPMAP_DATA){ //hapmap }else if (command == "OK"){ String[] returnStrings = {genoFileField.getText(), infoFileField.getText(), maxComparisonDistField.getText()}; if (fileType == HAPS){ caller.readPhasedGenotypes(returnStrings); }else if (fileType == PED){ caller.readPedGenotypes(returnStrings); } this.dispose(); }else if (command == "Cancel"){ this.dispose(); } }
if ( date == null ) { return ""; }
public String format() { long lAccuracy = (long) (accuracy * 24 * 3600 * 1000); String dateStr = ""; if ( accuracy > 0 ) { // Find the correct format to use String formatStr =accuracyFormatStrings[0]; for ( int i = 1; i < accuracyFormatLimits.length; i++ ) { if ( accuracy < accuracyFormatLimits[i] ) { break; } formatStr =accuracyFormatStrings[i]; } // Show the limits of the accuracy range DateFormat df = new SimpleDateFormat( formatStr ); Date lower = new Date( date.getTime() - lAccuracy ); Date upper = new Date( date.getTime() + lAccuracy ); String lowerStr = df.format( lower ); String upperStr = df.format( upper ); dateStr = lowerStr; if ( !lowerStr.equals( upperStr ) ) { dateStr += " - " + upperStr; } } else { DateFormat df = new SimpleDateFormat( "dd.MM.yyyy k:mm" ); dateStr = df.format( date ); } return dateStr; }
TDT myTDT = new TDT(); myTDT.calcTDT(textData.chromosomes);
private void processFile(String fileName,boolean fileType,String infoFileName){ try { int outputType; long maxDistance; long negMaxDistance; HaploData textData; File OutputFile; File inputFile; inputFile = new File(fileName); if(!inputFile.exists()){ System.out.println("input file: " + fileName + " does not exist"); System.exit(1); } maxDistance = this.arg_distance * 1000; negMaxDistance = -maxDistance; outputType = this.arg_output; textData = new HaploData(); Vector result = null; if(!fileType){ //read in haps file textData.prepareHapsInput(inputFile); } else { //read in ped file PedFile ped; Vector pedFileStrings; BufferedReader reader; String line; boolean[] markerResultArray; ped = new PedFile(); pedFileStrings = new Vector(); reader = new BufferedReader(new FileReader(inputFile)); result = new Vector(); while((line = reader.readLine())!=null){ pedFileStrings.add(line); } ped.parse(pedFileStrings); if(!arg_skipCheck) { result = ped.check(); } markerResultArray = new boolean[ped.getNumMarkers()]; for (int i = 0; i < markerResultArray.length; i++){ if(this.arg_skipCheck) { markerResultArray[i] = true; } else if(((MarkerResult)result.get(i)).getRating() > 0) { markerResultArray[i] = true; } else { markerResultArray[i] = false; } } /* if(this.arg_ignoreMarkers.size()>0) { for(int i=0;i<this.arg_ignoreMarkers.size();i++){ int index = Integer.parseInt((String)this.arg_ignoreMarkers.get(i)); if(index>0 && index<markerResultArray.length){ markerResultArray[index] = false; if(!this.arg_quiet) { System.out.println("Ignoring marker " + (index)); } } } }*/ textData.linkageToChrom(markerResultArray,ped); } String name = fileName; String baseName = fileName.substring(0,name.length()-5); if(!infoFileName.equals("")) { File infoFile = new File(infoFileName); if(infoFile.exists()) { textData.prepareMarkerInput(infoFile,maxDistance); if(!arg_quiet){ System.out.println("Using marker file " + infoFile.getName()); } textData.infoKnown = true; } else if(!this.arg_quiet) { System.out.println("info file " + infoFileName + " does not exist"); } } else { File maybeInfo = new File(baseName + ".info"); if (maybeInfo.exists()){ textData.prepareMarkerInput(maybeInfo,maxDistance); if(!arg_quiet){ System.out.println("Using marker file " + maybeInfo.getName()); } textData.infoKnown = true; } } if(this.arg_showCheck && result != null) { System.out.println("Data check results:\n" + "Name\t\tObsHET\tPredHET\tHWpval\t%Geno\tFamTrio\tMendErr"); for(int i=0;i<result.size();i++){ MarkerResult currentResult = (MarkerResult)result.get(i); System.out.println( Chromosome.getMarker(i).getName() +"\t"+ currentResult.getObsHet() +"\t"+ currentResult.getPredHet() +"\t"+ currentResult.getHWpvalue() +"\t"+ currentResult.getGenoPercent() +"\t"+ currentResult.getFamTrioNum() +"\t"+ currentResult.getMendErrNum()); } } if(outputType != -1){ textData.generateDPrimeTable(maxDistance); Haplotype[][] haplos; switch(outputType){ case 0: OutputFile = new File(fileName + ".SFSblocks"); break; case 1: OutputFile = new File(fileName + ".4GAMblocks"); break; case 2: OutputFile = new File(fileName + ".MJDblocks"); break; default: OutputFile = new File(fileName + ".SFSblocks"); break; } //this handles output type ALL if(outputType == 3) { OutputFile = new File(fileName + ".SFSblocks"); textData.guessBlocks(0); haplos = textData.generateHaplotypes(textData.blocks, 1); textData.saveHapsToText(orderHaps(haplos, textData), textData.getMultiDprime(), OutputFile); OutputFile = new File(fileName + ".4GAMblocks"); textData.guessBlocks(1); haplos = textData.generateHaplotypes(textData.blocks, 1); textData.saveHapsToText(orderHaps(haplos, textData), textData.getMultiDprime(), OutputFile); OutputFile = new File(fileName + ".MJDblocks"); textData.guessBlocks(2); haplos = textData.generateHaplotypes(textData.blocks, 1); textData.saveHapsToText(orderHaps(haplos, textData), textData.getMultiDprime(), OutputFile); }else{ textData.guessBlocks(outputType); haplos = textData.generateHaplotypes(textData.blocks, 1); textData.saveHapsToText(orderHaps(haplos, textData), textData.getMultiDprime(), OutputFile); } } if(this.arg_dprime) { OutputFile = new File(fileName + ".DPRIME"); if (textData.filteredDPrimeTable != null){ textData.saveDprimeToText(OutputFile); }else{ //this means that we're just writing dprime so we won't //keep the (potentially huge) dprime table in memory but instead //write out one line at a time forget FileWriter saveDprimeWriter = new FileWriter(OutputFile); if (textData.infoKnown){ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\tDist\n"); long dist; PairwiseLinkage linkageResult; for (int i = 0; i < Chromosome.getFilteredSize(); i++){ for (int j = 0; j < Chromosome.getFilteredSize(); j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ dist = (Chromosome.getFilteredMarker(j)).getPosition() - (Chromosome.getFilteredMarker(i)).getPosition(); if (maxDistance > 0){ if ((dist > maxDistance || dist < negMaxDistance)){ continue; } } linkageResult = textData.computeDPrime(Chromosome.realIndex[i],Chromosome.realIndex[j]); if(linkageResult != null) { saveDprimeWriter.write(Chromosome.getFilteredMarker(i).getName() + "\t" + Chromosome.getFilteredMarker(j).getName() + "\t" + linkageResult.toString() + "\t" + dist + "\n"); } } } } }else{ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\n"); long dist; PairwiseLinkage linkageResult; for (int i = 0; i < Chromosome.getFilteredSize(); i++){ for (int j = 0; j < Chromosome.getFilteredSize(); j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ dist = (Chromosome.getFilteredMarker(j)).getPosition() - (Chromosome.getFilteredMarker(i)).getPosition(); if (maxDistance > 0){ if ((dist > maxDistance || dist < negMaxDistance)){ continue; } } linkageResult = textData.computeDPrime(Chromosome.realIndex[i],Chromosome.realIndex[j]); if(linkageResult != null) { saveDprimeWriter.write((Chromosome.realIndex[i]+1) + "\t" + (Chromosome.realIndex[j]+1) + "\t" + linkageResult + "\n"); } } } } } saveDprimeWriter.close(); } } if(fileType){ TDT myTDT = new TDT(); myTDT.calcTDT(textData.chromosomes); } } catch(IOException e){ System.err.println("An error has occured. This probably has to do with file input or output"); } catch(HaploViewException e){ System.err.println(e.getMessage()); } catch(PedFileException pfe) { System.err.println(pfe.getMessage()); } }
"Added user "+user.getName()+"/"+user.getPassword());
"Added user "+user.getName());
public ActionForward execute(WebContext context, ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { AccessController.canAccess(context.getUser(), ACL_ADD_USERS); User user = buildUser(actionForm); UserManager.getInstance().addUser(user); UserActivityLogger.getInstance().logActivity( context.getUser().getUsername(), "Added user "+user.getName()+"/"+user.getPassword()); return mapping.findForward(Forwards.SUCCESS); }
this.colorDPrime(STD_SCHEME);
DPrimeDisplay(HaploData h){ theData=h; this.setDoubleBuffered(true); addMouseListener(this); addMouseMotionListener(this); }
blockDispHeight = boxSize/2 + fm.getAscent();
blockDispHeight = boxSize/3 + fm.getAscent();
public Dimension getPreferredSize() { //loop through table to find deepest non-null comparison PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; int count = 0; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] != null){ if (count < y-x){ count = y-x; } } } } //add one so we don't clip bottom box count ++; Graphics g = this.getGraphics(); g.setFont(markerNameFont); FontMetrics fm = g.getFontMetrics(); if (printDetails){ blockDispHeight = boxSize/2 + fm.getAscent(); }else{ blockDispHeight = boxSize/2; } int high = 2*V_BORDER + count*boxSize/2 + blockDispHeight; chartSize = new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1),high); //this dimension is just the area taken up by the dprime chart //it is used in drawing the worldmap if (theData.infoKnown){ infoHeight = TICK_BOTTOM + widestMarkerName + TEXT_GAP; high += infoHeight; }else{ infoHeight=0; } int wide = 2*H_BORDER + boxSize*(dPrimeTable.length-1); Rectangle visRect = getVisibleRect(); //big datasets often scroll way offscreen in zoom-out mode //but aren't the full height of the viewport if (high < visRect.height && showWM){ high = visRect.height; } return new Dimension(wide, high); }
blockDispHeight = boxSize/2;
blockDispHeight = boxSize/3;
public Dimension getPreferredSize() { //loop through table to find deepest non-null comparison PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; int count = 0; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] != null){ if (count < y-x){ count = y-x; } } } } //add one so we don't clip bottom box count ++; Graphics g = this.getGraphics(); g.setFont(markerNameFont); FontMetrics fm = g.getFontMetrics(); if (printDetails){ blockDispHeight = boxSize/2 + fm.getAscent(); }else{ blockDispHeight = boxSize/2; } int high = 2*V_BORDER + count*boxSize/2 + blockDispHeight; chartSize = new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1),high); //this dimension is just the area taken up by the dprime chart //it is used in drawing the worldmap if (theData.infoKnown){ infoHeight = TICK_BOTTOM + widestMarkerName + TEXT_GAP; high += infoHeight; }else{ infoHeight=0; } int wide = 2*H_BORDER + boxSize*(dPrimeTable.length-1); Rectangle visRect = getVisibleRect(); //big datasets often scroll way offscreen in zoom-out mode //but aren't the full height of the viewport if (high < visRect.height && showWM){ high = visRect.height; } return new Dimension(wide, high); }
refresh();
refresh(0); } else if (whichMarker > 0 && whichMarker < Chromosome.realIndex.length){ theData.addMarkerIntoSurroundingBlock(whichMarker);
public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { int clickX = e.getX(); int clickY = e.getY(); if (showWM && worldmapRect.contains(clickX,clickY)){ //convert a click on the worldmap to a point on the big picture int bigClickX = (((clickX - getVisibleRect().x) * chartSize.width) / worldmap.getWidth())-getVisibleRect().width/2; int bigClickY = (((clickY - getVisibleRect().y - (getVisibleRect().height-worldmap.getHeight())) * chartSize.height) / worldmap.getHeight()) - getVisibleRect().height/2 + infoHeight; //if the clicks are near the edges, correct values if (bigClickX > chartSize.width - getVisibleRect().width){ bigClickX = chartSize.width - getVisibleRect().width; } if (bigClickX < 0){ bigClickX = 0; } if (bigClickY > chartSize.height - getVisibleRect().height + infoHeight){ bigClickY = chartSize.height - getVisibleRect().height + infoHeight; } if (bigClickY < 0){ bigClickY = 0; } ((JViewport)getParent()).setViewPosition(new Point(bigClickX,bigClickY)); }else{ Rectangle blockselector = new Rectangle(clickXShift-boxRadius,clickYShift - boxRadius, (Chromosome.getFilteredSize()*boxSize), boxSize); if(blockselector.contains(clickX,clickY)){ int whichMarker = (int)(0.5 + (double)((clickX - clickXShift))/boxSize); if (theData.isInBlock[whichMarker]){ theData.removeFromBlock(whichMarker); refresh(); } } } } }
refresh();
refresh(0);
public void mouseReleased(MouseEvent e) { //remove popped up window if ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK){ popupExists = false; repaint(); //resize window once user has ceased dragging } else if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK){ if (getCursor() == Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR)){ resizeRectExists = false; noImage = true; if (resizeWMRect.width > 20){ wmMaxWidth = resizeWMRect.width; } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); repaint(); } if (getCursor() == Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)){ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); blockRectExists = false; int firstMarker = (int)(0.5 + (double)((blockStartX - clickXShift))/boxSize); int lastMarker = (int)(0.5 + (double)((e.getX() - clickXShift))/boxSize); if (firstMarker > lastMarker){ int temp = firstMarker; firstMarker = lastMarker; lastMarker = temp; } theData.addBlock(firstMarker, lastMarker); refresh(); } } }
g2.setFont(markerNameFont);
g2.setFont(boldMarkerNameFont);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1);
g2.fillRect(left + lineLeft+1, top+1, lineSpan-1, TICK_HEIGHT-1);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT);
g2.drawRect(left + lineLeft, top, lineSpan, TICK_HEIGHT);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT);
g2.drawLine(xx, top, xx, top + TICK_HEIGHT);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM;
g2.drawLine(xx, top + TICK_HEIGHT, left + i*boxSize, top+TICK_BOTTOM); } top += TICK_BOTTOM + TICK_HEIGHT;
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2);
g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/3);
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Rectangle visRect = getVisibleRect(); //deal with zooming if (chartSize.getWidth() > (3*visRect.width)){ showWM = true; }else{ showWM = false; } if (zoomLevel == 0){ printDetails = true; } else{ printDetails = false; } Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. if (!forExport){ if (!theData.infoKnown){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } else { g2.translate((size.width - pref.width) / 2, 0); } } //System.out.println(size + " " + pref); FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); //TODO: finish implementing scaling gizmo /*//deal with adding some space to better display data with large gaps int cumulativeGap[] = new int[Chromosome.getFilteredSize()]; for (int i = 0; i < cumulativeGap.length; i++){ cumulativeGap[i] = 0; } if (theData.infoKnown){ double mean = (((SNP)Chromosome.markers[Chromosome.markers.length-1]).getPosition() - ((SNP)Chromosome.markers[0]).getPosition())/Chromosome.markers.length-1; for (int i = 1; i < cumulativeGap.length; i++){ double sep = Chromosome.getMarker(i).getPosition() - Chromosome.getMarker(i-1).getPosition(); if (sep > mean*10){ cumulativeGap[i] = cumulativeGap[i-1] + (int)(sep/mean)*4; }else{ cumulativeGap[i] = cumulativeGap[i-1]; } } } */ if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft+1, 6, lineSpan-1, TICK_HEIGHT-1); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[x]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } if (forExport){ lowX = 0; lowY = 0; highX = dPrimeTable.length; highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } boolean even = true; //highlight blocks g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); } //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); if (printDetails){ String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } } g2.setStroke(thickerStroke); //see if the user has right-clicked to popup some marker info if(popupExists){ int smallDatasetSlopH = 0; int smallDatasetSlopV = 0; if (pref.getWidth() < visRect.width){ //dumb bug where little datasets popup the box in the wrong place smallDatasetSlopH = (int)(visRect.width - pref.getWidth())/2; smallDatasetSlopV = (int)(visRect.height - pref.getHeight())/2; } g2.setColor(Color.white); g2.fillRect(popupDrawRect.x+1-smallDatasetSlopH, popupDrawRect.y+1-smallDatasetSlopV, popupDrawRect.width-1, popupDrawRect.height-1); g2.setColor(Color.black); g2.drawRect(popupDrawRect.x-smallDatasetSlopH, popupDrawRect.y-smallDatasetSlopV, popupDrawRect.width, popupDrawRect.height); for (int x = 0; x < 5; x++){ g.drawString(displayStrings[x],popupDrawRect.x + popupLeftMargin-smallDatasetSlopH, popupDrawRect.y+((x+1)*metrics.getHeight())-smallDatasetSlopV); } } if (showWM && !forExport){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_GAP = 1; final int WM_BD_HEIGHT = 2; final int WM_BD_TOTAL = WM_BD_HEIGHT + 2*WM_BD_GAP; if (wmMaxWidth == 0){ wmMaxWidth = visRect.width/3; } double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth(),worldmap.getHeight()); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth(), worldmap.getHeight()); double prefBoxSize = boxSize/(scalefactor*((double)wmMaxWidth/(double)(wmMaxWidth-WM_BD_TOTAL))); float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset+WM_BD_GAP, (int)((last-first+1)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } wmResizeCorner = new Rectangle(visRect.x + worldmap.getWidth() - (worldmap.getWidth()-ir.width)/2, visRect.y + visRect.height - worldmap.getHeight(), (worldmap.getWidth()-ir.width)/2, (worldmap.getHeight() -ir.height)/2); g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } //see if we're drawing a worldmap resize rect if (resizeRectExists){ g2.setColor(Color.black); g2.drawRect(resizeWMRect.x, resizeWMRect.y, resizeWMRect.width, resizeWMRect.height); } //see if we're drawing a block selector rect if (blockRectExists){ g2.setColor(Color.black); g2.setStroke(dashedThinStroke); g2.drawRect(blockRect.x, blockRect.y, blockRect.width, blockRect.height); } }
public void refresh(){
public void refresh(int scheme){ if (scheme != 0){ colorDPrime(scheme); }
public void refresh(){ noImage = true; repaint(); }
dataSet(data, 0, this.base_offset, Math.min(this.data_length, data.length));
dataSet(data, 0, 0, Math.min(this.data_length, data.length));
public void dataSet(byte[] data) { dataSet(data, 0, this.base_offset, Math.min(this.data_length, data.length)); }
public void execute() { finished = false;
public void execute() { if (cancelled || finished) return;
public void execute() { finished = false; stmtsTried = 0; stmtsCompleted = 0; SQLDatabase target = architectFrame.playpen.getDatabase(); Connection con; Statement stmt; try { con = target.getConnection(); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't connect to target database: "+fex.getMessage() +"\nPlease check the connection settings and try again."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } catch (Exception ex) { logger.error("Unexpected exception in DDL generation", ex); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } try { stmt = con.createStatement(); statements = ddlg.generateDDLStatements(target); } catch (SQLException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database."); } }); finished = true; return; } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); } }); finished = true; return; } try { logWriter = new LogWriter(ArchitectSession.getInstance().getUserSettings().getDDLUserSettings().getDDLLogPath()); logWriter.info("Starting DDL Generation at " + new java.util.Date(System.currentTimeMillis())); logWriter.info("Database Target: " + target.getConnectionSpec()); Iterator it = statements.iterator(); while (it.hasNext() && !finished) { DDLStatement ddlStmt = (DDLStatement) it.next(); try { List conflictingTargetObjects = DDLUtils.findConflicting(con, ddlStmt); if (conflictingTargetObjects.size() > 0) { int decision = JOptionPane.showConfirmDialog (dialog, "The target database already contains object(s) with\n" +"the same name(s) as those you want to create:\n\n" +conflictingTargetObjects +"\nDo you want to drop the existing target objects?\n", "Conflicting Objects Found", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { DDLUtils.dropConflicting(con, conflictingTargetObjects); } } stmtsTried++; logWriter.info("executing: " + ddlStmt.getSQLText()); stmt.executeUpdate(ddlStmt.getSQLText()); stmtsCompleted++; } catch (SQLException ex) { final Exception fex = ex; final String fsql = ddlStmt.getSQLText(); logWriter.info("sql statement failed: " + ex.getMessage()); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { int decision = JOptionPane.showConfirmDialog (dialog, "SQL statement failed: "+fex.getMessage() +"\nThe statement was:\n"+fsql+"\nDo you want to continue?", "SQL Failure", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.NO_OPTION) { logWriter.info("Export cancelled by user."); cancelJob(); } } }); } catch (InterruptedException ex2) { logger.warn("DDL Worker was interrupted during InvokeAndWait", ex2); } catch (InvocationTargetException ex2) { final Exception fex2 = ex2; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Worker thread died: "+fex2.getMessage()); } }); } if (isCancelled()) { finished = true; // don't return, we might as well display how many statements ended up being processed... } } } logWriter.info("Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "A problem with the DDL log file prevented\n" +"DDL generation from running:\n\n" +fex.getMessage()); } }); finished = true; } finally { // flush and close the LogWriter logWriter.flush(); logWriter.close(); logWriter=null; } try { stmt.close(); } catch (SQLException ex) { logger.error("SQLException while closing statement", ex); } // show them what they've won! SwingUtilities.invokeLater(new Runnable() { public void run() { String message = "Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."; if (stmtsCompleted == 0 && stmtsTried > 0) { message += ("\nBetter luck next time!"); } JOptionPane.showMessageDialog(dialog, message); } }); finished = true; }
statements = ddlg.generateDDLStatements(target);
public void execute() { finished = false; stmtsTried = 0; stmtsCompleted = 0; SQLDatabase target = architectFrame.playpen.getDatabase(); Connection con; Statement stmt; try { con = target.getConnection(); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't connect to target database: "+fex.getMessage() +"\nPlease check the connection settings and try again."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } catch (Exception ex) { logger.error("Unexpected exception in DDL generation", ex); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } try { stmt = con.createStatement(); statements = ddlg.generateDDLStatements(target); } catch (SQLException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database."); } }); finished = true; return; } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); } }); finished = true; return; } try { logWriter = new LogWriter(ArchitectSession.getInstance().getUserSettings().getDDLUserSettings().getDDLLogPath()); logWriter.info("Starting DDL Generation at " + new java.util.Date(System.currentTimeMillis())); logWriter.info("Database Target: " + target.getConnectionSpec()); Iterator it = statements.iterator(); while (it.hasNext() && !finished) { DDLStatement ddlStmt = (DDLStatement) it.next(); try { List conflictingTargetObjects = DDLUtils.findConflicting(con, ddlStmt); if (conflictingTargetObjects.size() > 0) { int decision = JOptionPane.showConfirmDialog (dialog, "The target database already contains object(s) with\n" +"the same name(s) as those you want to create:\n\n" +conflictingTargetObjects +"\nDo you want to drop the existing target objects?\n", "Conflicting Objects Found", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { DDLUtils.dropConflicting(con, conflictingTargetObjects); } } stmtsTried++; logWriter.info("executing: " + ddlStmt.getSQLText()); stmt.executeUpdate(ddlStmt.getSQLText()); stmtsCompleted++; } catch (SQLException ex) { final Exception fex = ex; final String fsql = ddlStmt.getSQLText(); logWriter.info("sql statement failed: " + ex.getMessage()); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { int decision = JOptionPane.showConfirmDialog (dialog, "SQL statement failed: "+fex.getMessage() +"\nThe statement was:\n"+fsql+"\nDo you want to continue?", "SQL Failure", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.NO_OPTION) { logWriter.info("Export cancelled by user."); cancelJob(); } } }); } catch (InterruptedException ex2) { logger.warn("DDL Worker was interrupted during InvokeAndWait", ex2); } catch (InvocationTargetException ex2) { final Exception fex2 = ex2; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Worker thread died: "+fex2.getMessage()); } }); } if (isCancelled()) { finished = true; // don't return, we might as well display how many statements ended up being processed... } } } logWriter.info("Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "A problem with the DDL log file prevented\n" +"DDL generation from running:\n\n" +fex.getMessage()); } }); finished = true; } finally { // flush and close the LogWriter logWriter.flush(); logWriter.close(); logWriter=null; } try { stmt.close(); } catch (SQLException ex) { logger.error("SQLException while closing statement", ex); } // show them what they've won! SwingUtilities.invokeLater(new Runnable() { public void run() { String message = "Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."; if (stmtsCompleted == 0 && stmtsTried > 0) { message += ("\nBetter luck next time!"); } JOptionPane.showMessageDialog(dialog, message); } }); finished = true; }
} catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); } }); finished = true; return;
public void execute() { finished = false; stmtsTried = 0; stmtsCompleted = 0; SQLDatabase target = architectFrame.playpen.getDatabase(); Connection con; Statement stmt; try { con = target.getConnection(); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't connect to target database: "+fex.getMessage() +"\nPlease check the connection settings and try again."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } catch (Exception ex) { logger.error("Unexpected exception in DDL generation", ex); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } try { stmt = con.createStatement(); statements = ddlg.generateDDLStatements(target); } catch (SQLException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database."); } }); finished = true; return; } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); } }); finished = true; return; } try { logWriter = new LogWriter(ArchitectSession.getInstance().getUserSettings().getDDLUserSettings().getDDLLogPath()); logWriter.info("Starting DDL Generation at " + new java.util.Date(System.currentTimeMillis())); logWriter.info("Database Target: " + target.getConnectionSpec()); Iterator it = statements.iterator(); while (it.hasNext() && !finished) { DDLStatement ddlStmt = (DDLStatement) it.next(); try { List conflictingTargetObjects = DDLUtils.findConflicting(con, ddlStmt); if (conflictingTargetObjects.size() > 0) { int decision = JOptionPane.showConfirmDialog (dialog, "The target database already contains object(s) with\n" +"the same name(s) as those you want to create:\n\n" +conflictingTargetObjects +"\nDo you want to drop the existing target objects?\n", "Conflicting Objects Found", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { DDLUtils.dropConflicting(con, conflictingTargetObjects); } } stmtsTried++; logWriter.info("executing: " + ddlStmt.getSQLText()); stmt.executeUpdate(ddlStmt.getSQLText()); stmtsCompleted++; } catch (SQLException ex) { final Exception fex = ex; final String fsql = ddlStmt.getSQLText(); logWriter.info("sql statement failed: " + ex.getMessage()); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { int decision = JOptionPane.showConfirmDialog (dialog, "SQL statement failed: "+fex.getMessage() +"\nThe statement was:\n"+fsql+"\nDo you want to continue?", "SQL Failure", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.NO_OPTION) { logWriter.info("Export cancelled by user."); cancelJob(); } } }); } catch (InterruptedException ex2) { logger.warn("DDL Worker was interrupted during InvokeAndWait", ex2); } catch (InvocationTargetException ex2) { final Exception fex2 = ex2; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Worker thread died: "+fex2.getMessage()); } }); } if (isCancelled()) { finished = true; // don't return, we might as well display how many statements ended up being processed... } } } logWriter.info("Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "A problem with the DDL log file prevented\n" +"DDL generation from running:\n\n" +fex.getMessage()); } }); finished = true; } finally { // flush and close the LogWriter logWriter.flush(); logWriter.close(); logWriter=null; } try { stmt.close(); } catch (SQLException ex) { logger.error("SQLException while closing statement", ex); } // show them what they've won! SwingUtilities.invokeLater(new Runnable() { public void run() { String message = "Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."; if (stmtsCompleted == 0 && stmtsTried > 0) { message += ("\nBetter luck next time!"); } JOptionPane.showMessageDialog(dialog, message); } }); finished = true; }
List conflictingTargetObjects = DDLUtils.findConflicting(con, ddlStmt); if (conflictingTargetObjects.size() > 0) { int decision = JOptionPane.showConfirmDialog (dialog, "The target database already contains object(s) with\n" +"the same name(s) as those you want to create:\n\n" +conflictingTargetObjects +"\nDo you want to drop the existing target objects?\n", "Conflicting Objects Found", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { DDLUtils.dropConflicting(con, conflictingTargetObjects); } }
public void execute() { finished = false; stmtsTried = 0; stmtsCompleted = 0; SQLDatabase target = architectFrame.playpen.getDatabase(); Connection con; Statement stmt; try { con = target.getConnection(); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't connect to target database: "+fex.getMessage() +"\nPlease check the connection settings and try again."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } catch (Exception ex) { logger.error("Unexpected exception in DDL generation", ex); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); } }); finished = true; return; } try { stmt = con.createStatement(); statements = ddlg.generateDDLStatements(target); } catch (SQLException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database."); } }); finished = true; return; } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); } }); finished = true; return; } try { logWriter = new LogWriter(ArchitectSession.getInstance().getUserSettings().getDDLUserSettings().getDDLLogPath()); logWriter.info("Starting DDL Generation at " + new java.util.Date(System.currentTimeMillis())); logWriter.info("Database Target: " + target.getConnectionSpec()); Iterator it = statements.iterator(); while (it.hasNext() && !finished) { DDLStatement ddlStmt = (DDLStatement) it.next(); try { List conflictingTargetObjects = DDLUtils.findConflicting(con, ddlStmt); if (conflictingTargetObjects.size() > 0) { int decision = JOptionPane.showConfirmDialog (dialog, "The target database already contains object(s) with\n" +"the same name(s) as those you want to create:\n\n" +conflictingTargetObjects +"\nDo you want to drop the existing target objects?\n", "Conflicting Objects Found", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { DDLUtils.dropConflicting(con, conflictingTargetObjects); } } stmtsTried++; logWriter.info("executing: " + ddlStmt.getSQLText()); stmt.executeUpdate(ddlStmt.getSQLText()); stmtsCompleted++; } catch (SQLException ex) { final Exception fex = ex; final String fsql = ddlStmt.getSQLText(); logWriter.info("sql statement failed: " + ex.getMessage()); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { int decision = JOptionPane.showConfirmDialog (dialog, "SQL statement failed: "+fex.getMessage() +"\nThe statement was:\n"+fsql+"\nDo you want to continue?", "SQL Failure", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.NO_OPTION) { logWriter.info("Export cancelled by user."); cancelJob(); } } }); } catch (InterruptedException ex2) { logger.warn("DDL Worker was interrupted during InvokeAndWait", ex2); } catch (InvocationTargetException ex2) { final Exception fex2 = ex2; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "Worker thread died: "+fex2.getMessage()); } }); } if (isCancelled()) { finished = true; // don't return, we might as well display how many statements ended up being processed... } } } logWriter.info("Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."); } catch (ArchitectException ex) { final Exception fex = ex; SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog (dialog, "A problem with the DDL log file prevented\n" +"DDL generation from running:\n\n" +fex.getMessage()); } }); finished = true; } finally { // flush and close the LogWriter logWriter.flush(); logWriter.close(); logWriter=null; } try { stmt.close(); } catch (SQLException ex) { logger.error("SQLException while closing statement", ex); } // show them what they've won! SwingUtilities.invokeLater(new Runnable() { public void run() { String message = "Successfully executed "+stmtsCompleted+" out of "+stmtsTried+" statements."; if (stmtsCompleted == 0 && stmtsTried > 0) { message += ("\nBetter luck next time!"); } JOptionPane.showMessageDialog(dialog, message); } }); finished = true; }
(dialog, "You have to specify a target database connection" +"\nbefore executing this script.");
(dialog, "Couldn't connect to target database: "+fex.getMessage() +"\nPlease check the connection settings and try again.");
public void run() { JOptionPane.showMessageDialog (dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog(); }
(dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database.");
(dialog, "You have to specify a target database connection" +"\nbefore executing this script."); ArchitectFrame.getMainInstance().playpen.showDbcsDialog();
public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was reported by the target database."); }
+"\nThe problem was detected internally to the Architect.");
+"\nThe problem was reported by the target database.");
public void run() { JOptionPane.showMessageDialog (dialog, "Couldn't generate DDL statements: "+fex.getMessage() +"\nThe problem was detected internally to the Architect."); }