import jalview.api.FeatureSettingsControllerI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcher;
import jalview.datamodel.features.FeatureMatcherI;
import jalview.datamodel.features.FeatureMatcherSet;
import jalview.datamodel.features.FeatureMatcherSetI;
import jalview.gui.Help.HelpId;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
-import jalview.schemabinding.version2.Filter;
-import jalview.schemabinding.version2.JalviewUserColours;
-import jalview.schemabinding.version2.MatcherSet;
import jalview.schemes.FeatureColour;
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
+import jalview.xml.binding.jalview.JalviewUserColours;
+import jalview.xml.binding.jalview.JalviewUserColours.Colour;
+import jalview.xml.binding.jalview.JalviewUserColours.Filter;
+import jalview.xml.binding.jalview.ObjectFactory;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
+import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
+import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
public class FeatureSettings extends JPanel
implements FeatureSettingsControllerI
private static final int MIN_HEIGHT = 400;
+ private final static String BASE_TOOLTIP = MessageManager.getString("label.click_to_edit");
+
final FeatureRenderer fr;
public final AlignFrame af;
int selectedRow = -1;
- JButton fetchDAS = new JButton();
-
- JButton saveDAS = new JButton();
-
- JButton cancelDAS = new JButton();
-
boolean resettingTable = false;
/*
{
String tip = null;
int column = table.columnAtPoint(e.getPoint());
+ int row = table.rowAtPoint(e.getPoint());
+
switch (column)
{
case TYPE_COLUMN:
tip = JvSwingUtils.wrapTooltip(true, MessageManager
.getString("label.feature_settings_click_drag"));
break;
+ case COLOUR_COLUMN:
+ FeatureColourI colour = (FeatureColourI) table.getValueAt(row,
+ column);
+ tip = getColorTooltip(colour, true);
+ break;
case FILTER_COLUMN:
- int row = table.rowAtPoint(e.getPoint());
FeatureMatcherSet o = (FeatureMatcherSet) table.getValueAt(row,
column);
tip = o.isEmpty()
default:
break;
}
+
return tip;
}
+
+ /**
+ * Position the tooltip near the bottom edge of, and half way across, the
+ * current cell
+ */
+ @Override
+ public Point getToolTipLocation(MouseEvent e)
+ {
+ Point point = e.getPoint();
+ int column = table.columnAtPoint(point);
+ int row = table.rowAtPoint(point);
+ Rectangle r = getCellRect(row, column, false);
+ Point loc = new Point(r.x + r.width / 2, r.y + r.height - 3);
+ return loc;
+ }
};
- table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
+ JTableHeader tableHeader = table.getTableHeader();
+ tableHeader.setFont(new Font("Verdana", Font.PLAIN, 12));
+ tableHeader.setReorderingAllowed(false);
table.setFont(new Font("Verdana", Font.PLAIN, 12));
- // table.setDefaultRenderer(Color.class, new ColorRenderer());
- // table.setDefaultEditor(Color.class, new ColorEditor(this));
- //
table.setDefaultEditor(FeatureColour.class, new ColorEditor(this));
table.setDefaultRenderer(FeatureColour.class, new ColorRenderer());
data[dataIndex][FILTER_COLUMN] = featureFilter == null
? new FeatureMatcherSet()
: featureFilter;
- data[dataIndex][SHOW_COLUMN] = new Boolean(
+ data[dataIndex][SHOW_COLUMN] = Boolean.valueOf(
af.getViewport().getFeaturesDisplayed().isVisible(type));
dataIndex++;
displayableTypes.remove(type);
data[dataIndex][FILTER_COLUMN] = featureFilter == null
? new FeatureMatcherSet()
: featureFilter;
- data[dataIndex][SHOW_COLUMN] = new Boolean(true);
+ data[dataIndex][SHOW_COLUMN] = Boolean.valueOf(true);
dataIndex++;
displayableTypes.remove(type);
}
InputStreamReader in = new InputStreamReader(
new FileInputStream(file), "UTF-8");
- JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
+ JAXBContext jc = JAXBContext
+ .newInstance("jalview.xml.binding.jalview");
+ javax.xml.bind.Unmarshaller um = jc.createUnmarshaller();
+ XMLStreamReader streamReader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(in);
+ JAXBElement<JalviewUserColours> jbe = um.unmarshal(streamReader,
+ JalviewUserColours.class);
+ JalviewUserColours jucs = jbe.getValue();
+
+ // JalviewUserColours jucs = JalviewUserColours.unmarshal(in);
/*
* load feature colours
*/
- for (int i = jucs.getColourCount() - 1; i >= 0; i--)
+ for (int i = jucs.getColour().size() - 1; i >= 0; i--)
{
- jalview.schemabinding.version2.Colour newcol = jucs.getColour(i);
- FeatureColourI colour = Jalview2XML.unmarshalColour(newcol);
+ Colour newcol = jucs.getColour().get(i);
+ FeatureColourI colour = jalview.project.Jalview2XML
+ .parseColour(newcol);
fr.setColour(newcol.getName(), colour);
- fr.setOrder(newcol.getName(), i / (float) jucs.getColourCount());
+ fr.setOrder(newcol.getName(), i / (float) jucs.getColour().size());
}
/*
* load feature filters; loaded filters will replace any that are
* currently defined, other defined filters are left unchanged
*/
- for (int i = 0; i < jucs.getFilterCount(); i++)
+ for (int i = 0; i < jucs.getFilter().size(); i++)
{
- jalview.schemabinding.version2.Filter filterModel = jucs
- .getFilter(i);
+ Filter filterModel = jucs.getFilter().get(i);
String featureType = filterModel.getFeatureType();
- FeatureMatcherSetI filter = Jalview2XML.unmarshalFilter(featureType,
- filterModel.getMatcherSet());
+ FeatureMatcherSetI filter = jalview.project.Jalview2XML
+ .parseFilter(featureType, filterModel.getMatcherSet());
if (!filter.isEmpty())
{
fr.setFeatureFilter(featureType, filter);
for (String featureType : sortedTypes)
{
FeatureColourI fcol = fr.getFeatureStyle(featureType);
- jalview.schemabinding.version2.Colour col = Jalview2XML.marshalColour(
- featureType, fcol);
- ucs.addColour(col);
+ Colour col = jalview.project.Jalview2XML.marshalColour(featureType,
+ fcol);
+ ucs.getColour().add(col);
}
/*
{
Iterator<FeatureMatcherI> iterator = filter.getMatchers().iterator();
FeatureMatcherI firstMatcher = iterator.next();
- MatcherSet ms = Jalview2XML.marshalFilter(firstMatcher, iterator,
+ jalview.xml.binding.jalview.FeatureMatcherSet ms = jalview.project.Jalview2XML
+ .marshalFilter(firstMatcher, iterator,
filter.isAnded());
Filter filterModel = new Filter();
filterModel.setFeatureType(featureType);
filterModel.setMatcherSet(ms);
- ucs.addFilter(filterModel);
+ ucs.getFilter().add(filterModel);
}
}
+ JAXBContext jaxbContext = JAXBContext
+ .newInstance(JalviewUserColours.class);
+ Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
+ jaxbMarshaller.marshal(
+ new ObjectFactory().createJalviewUserColours(ucs), out);
- ucs.marshal(out);
+ // jaxbMarshaller.marshal(object, pout);
+ // marshaller.marshal(object);
+ out.flush();
+
+ // ucs.marshal(out);
out.close();
} catch (Exception ex)
{
}
}
});
- help.setFont(JvSwingUtils.getLabelFont());
- help.setText(MessageManager.getString("action.help"));
- help.addActionListener(new ActionListener()
- {
- @Override
- public void actionPerformed(ActionEvent e)
- {
- try
- {
- Help.showHelpWindow(HelpId.SequenceFeatureSettings);
- } catch (HelpSetException e1)
- {
- e1.printStackTrace();
- }
- }
- });
JButton cancel = new JButton(MessageManager.getString("action.cancel"));
cancel.setFont(JvSwingUtils.getLabelFont());
this.add(settingsPane);
}
+ /**
+ * Answers a suitable tooltip to show on the colour cell of the table
+ *
+ * @param fcol
+ * @param withHint
+ * if true include 'click to edit' and similar text
+ * @return
+ */
+ public static String getColorTooltip(FeatureColourI fcol,
+ boolean withHint)
+ {
+ if (fcol == null)
+ {
+ return null;
+ }
+ if (fcol.isSimpleColour())
+ {
+ return withHint ? BASE_TOOLTIP : null;
+ }
+ String description = fcol.getDescription();
+ description = description.replaceAll("<", "<");
+ description = description.replaceAll(">", ">");
+ StringBuilder tt = new StringBuilder(description);
+ if (withHint)
+ {
+ tt.append("<br>").append(BASE_TOOLTIP).append("</br>");
+ }
+ return JvSwingUtils.wrapTooltip(true, tt.toString());
+ }
+
+ public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
+ int w, int h)
+ {
+ boolean thr = false;
+ StringBuilder tx = new StringBuilder();
+
+ if (gcol.isColourByAttribute())
+ {
+ tx.append(FeatureMatcher
+ .toAttributeDisplayName(gcol.getAttributeName()));
+ }
+ else if (!gcol.isColourByLabel())
+ {
+ tx.append(MessageManager.getString("label.score"));
+ }
+ tx.append(" ");
+ if (gcol.isAboveThreshold())
+ {
+ thr = true;
+ tx.append(">");
+ }
+ if (gcol.isBelowThreshold())
+ {
+ thr = true;
+ tx.append("<");
+ }
+ if (gcol.isColourByLabel())
+ {
+ if (thr)
+ {
+ tx.append(" ");
+ }
+ if (!gcol.isColourByAttribute())
+ {
+ tx.append("Label");
+ }
+ comp.setIcon(null);
+ }
+ else
+ {
+ Color newColor = gcol.getMaxColour();
+ comp.setBackground(newColor);
+ // System.err.println("Width is " + w / 2);
+ Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
+ comp.setIcon(ficon);
+ // tt+="RGB value: Max (" + newColor.getRed() + ", "
+ // + newColor.getGreen() + ", " + newColor.getBlue()
+ // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
+ // + ", " + minCol.getBlue() + ")");
+ }
+ comp.setHorizontalAlignment(SwingConstants.CENTER);
+ comp.setText(tx.toString());
+ }
+
// ///////////////////////////////////////////////////////////////////////
// http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
// ///////////////////////////////////////////////////////////////////////
class ColorRenderer extends JLabel implements TableCellRenderer
{
- javax.swing.border.Border unselectedBorder = null;
-
- javax.swing.border.Border selectedBorder = null;
+ Border unselectedBorder = null;
- final String baseTT = "Click to edit, right/apple click for menu.";
+ Border selectedBorder = null;
public ColorRenderer()
{
{
FeatureColourI cellColour = (FeatureColourI) color;
setOpaque(true);
- setToolTipText(baseTT);
setBackground(tbl.getBackground());
if (!cellColour.isSimpleColour())
{
renderGraduatedColor(comp, gcol, w, h);
}
- public static void renderGraduatedColor(JLabel comp, FeatureColourI gcol,
- int w, int h)
- {
- boolean thr = false;
- StringBuilder tt = new StringBuilder();
- StringBuilder tx = new StringBuilder();
-
- if (gcol.isColourByAttribute())
- {
- tx.append(String.join(":", gcol.getAttributeName()));
- }
- else if (!gcol.isColourByLabel())
- {
- tx.append(MessageManager.getString("label.score"));
- }
- tx.append(" ");
- if (gcol.isAboveThreshold())
- {
- thr = true;
- tx.append(">");
- tt.append("Thresholded (Above ").append(gcol.getThreshold())
- .append(") ");
- }
- if (gcol.isBelowThreshold())
- {
- thr = true;
- tx.append("<");
- tt.append("Thresholded (Below ").append(gcol.getThreshold())
- .append(") ");
- }
- if (gcol.isColourByLabel())
- {
- tt.append("Coloured by label text. ").append(tt);
- if (thr)
- {
- tx.append(" ");
- }
- if (!gcol.isColourByAttribute())
- {
- tx.append("Label");
- }
- comp.setIcon(null);
- }
- else
- {
- Color newColor = gcol.getMaxColour();
- comp.setBackground(newColor);
- // System.err.println("Width is " + w / 2);
- Icon ficon = new FeatureIcon(gcol, comp.getBackground(), w, h, thr);
- comp.setIcon(ficon);
- // tt+="RGB value: Max (" + newColor.getRed() + ", "
- // + newColor.getGreen() + ", " + newColor.getBlue()
- // + ")\nMin (" + minCol.getRed() + ", " + minCol.getGreen()
- // + ", " + minCol.getBlue() + ")");
- }
- comp.setHorizontalAlignment(SwingConstants.CENTER);
- comp.setText(tx.toString());
- if (tt.length() > 0)
- {
- if (comp.getToolTipText() == null)
- {
- comp.setToolTipText(tt.toString());
- }
- else
- {
- comp.setToolTipText(
- tt.append(" ").append(comp.getToolTipText()).toString());
- }
- }
- }
-
class ColorEditor extends AbstractCellEditor
implements TableCellEditor, ActionListener
{
button.setOpaque(true);
button.setBackground(me.getBackground());
button.setText(currentFilter.toString());
- button.setToolTipText(currentFilter.toString());
button.setIcon(null);
return button;
}