/** * PlasmidPanel constructor coming from a Viewer object, in which case the panel that this * PlasmidPanel should be in comes from the topPanel in the Viewer class * * @param p the plasmid to view * @param parent the Viewer object this PlasmidPanel lives in */ public PlasmidPanel(org.autogene.core.bio.entities.Plasmid p, Viewer parent) { this(p, parent.getTopPanel(), parent); home = parent; previousWidth = -1; previousHeight = -1; setOpaque(false); }
@Override public void mousePressed(MouseEvent me) { /* Check to see if we clicked a label */ int x = me.getX(), y = me.getY(); Feature selectedFeature = null; ArrayList<OuterLabel> outerLabels = cgview.getOuterLabels(); OuterLabel ol = null; for (int o = 0; o < outerLabels.size(); o++) { ol = outerLabels.get(o); Rectangle2D rect = ol.getBounds(); double rectX = rect.getX(), rectY = rect.getY(), rectW = rect.getWidth(), rectH = rect.getHeight(); if (x > rectX && x < (rectX + rectW) && y > rectY && y < (rectY + rectH)) { ArrayList<FeatureSlot> featureSlots = cgview.getFeatureSlots(); for (int i = 0; i < featureSlots.size(); i++) { FeatureSlot fs = featureSlots.get(i); ArrayList<Feature> features = fs.getFeatures(); for (int j = 0; j < features.size(); j++) { Feature f = features.get(j); String featureLabel = f.getLabel(); if (featureLabel.equals(ol.getLabelText())) { selectedFeature = f; break; } if (selectedFeature != null) break; } if (selectedFeature != null) break; } } if (selectedFeature != null) break; } /* If we have selected a feature, either make it appear selected or * deselected. */ if (selectedFeature != null) { // paint the feature on the cgview Annotation a = findAnnotationOfFeature(selectedFeature); Color toUse = (a.getScore() == 1.0) ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH; Color fColor = selectedFeature.getColor(); Color blue = (a.getScore() == 1.0) ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH; Color orange = ColorConstants.ROW_SELECTED_COLOR; boolean isBlue = fColor.getRed() == blue.getRed() && fColor.getGreen() == blue.getGreen() && fColor.getBlue() == blue.getBlue(); boolean isOrange = fColor.getRed() == orange.getRed() && fColor.getGreen() == orange.getGreen() && fColor.getBlue() == orange.getBlue(); Color turq = ColorConstants.CUSTOM_ANNOTATION_COLOR; boolean isTurquoise = fColor.getRed() == turq.getRed() && fColor.getGreen() == turq.getGreen() && fColor.getBlue() == turq.getBlue(); Color ye = ColorConstants.VIEW_FEATURE_FROM_PRIVATE_REGISTRY_COLOR; boolean isYellow = fColor.getRed() == ye.getRed() && fColor.getGreen() == ye.getGreen() && fColor.getBlue() == ye.getBlue(); if (isBlue || isOrange || isTurquoise || isYellow) { toUse = ColorConstants.SELECTED_COLOR; selectedFeatures.add(selectedFeature.getLabel()); } else if (((MyTableModel) home.getTable().getModel()) .isFeatureSelected(selectedFeature.getLabel())) { toUse = ColorConstants.ROW_SELECTED_COLOR; selectedFeatures.remove(selectedFeature.getLabel()); } else { toUse = (a.getScore() == 1.0) ? ColorConstants.NEUTRAL_COLOR_PERFECT_MATCH : ColorConstants.NEUTRAL_COLOR_IMPERFECT_MATCH; selectedFeatures.remove(selectedFeature.getLabel()); } selectedFeature.setColor(toUse); ArrayList<FeatureRange> f = selectedFeature.getRanges(); for (int n = 0; n < f.size(); n++) { f.get(n).setColor(toUse); } // ol.setColor(Color.red); repaint(); // highlight text in the textpane FeatureRange fr = (FeatureRange) selectedFeature.getRanges().get(0); if (home != null) home.highlightDNA(fr); } else { System.out.println("selected feature is null"); } }