Unnamed: 0
int64
0
2.05k
func
stringlengths
27
124k
target
bool
2 classes
project
stringlengths
39
117
1,900
@SuppressWarnings("serial") public final class CenterPanePanel extends View implements SelectionProvider { private static ResourceBundle bundle = ResourceBundle.getBundle("ExampleResourceBundle"); //NOI18N private final JList list; // list representing the selected element private final CenterPanePanel.CenterPaneListModel model; public CenterPanePanel(AbstractComponent ac, ViewInfo vi) { super(ac,vi); setLayout(new BorderLayout()); list = new JList(model = new CenterPaneListModel(getManifestedComponent())); list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(list,BorderLayout.CENTER); // the list has changed, so fire a selection event so that interested listeners // can respond list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { firePropertyChange(SelectionProvider.SELECTION_CHANGED_PROP, null, getSelectedManifestations()); } }); } @Override public void updateMonitoredGUI(AddChildEvent event) { // a new child has been added, notify the list view listChanged(); } @Override public void updateMonitoredGUI(RemoveChildEvent event) { // a child has been removed, notify the list view listChanged(); } @Override public SelectionProvider getSelectionProvider() { return this; } private void listChanged() { for (ListDataListener listener : model.getListDataListeners()) { listener.contentsChanged(new ListDataEvent(list, ListDataEvent.CONTENTS_CHANGED,0,model.getSize())); } } /** * A simple list model for displaying the children of a component. */ private static class CenterPaneListModel extends AbstractListModel { private final AbstractComponent component; public CenterPaneListModel(AbstractComponent aComponent) { component = aComponent; } @Override public Object getElementAt(int index) { return component.getComponents().get(index).getDisplayName(); } @Override public int getSize() { return component.getComponents().size(); } } @Override public void addSelectionChangeListener(PropertyChangeListener listener) { addPropertyChangeListener(SelectionProvider.SELECTION_CHANGED_PROP, listener); } @Override public void clearCurrentSelections() { list.clearSelection(); } @Override public Collection<View> getSelectedManifestations() { int[] selected = list.getSelectedIndices(); // iterate over the list of selected items in the list and create manifestations List<View> selections = new ArrayList<View>(selected.length); List<AbstractComponent> children = getManifestedComponent().getComponents(); for (int selectedIndex:selected) { AbstractComponent comp = children.get(selectedIndex); Set<ViewInfo> views = comp.getViewInfos(ViewType.NODE); // there should always be a node view for a component ViewInfo nodeView = views.iterator().next(); selections.add(nodeView.createView(comp)); } return selections; } @Override public void removeSelectionChangeListener( PropertyChangeListener listener) { removePropertyChangeListener(SelectionProvider.SELECTION_CHANGED_PROP, listener); } }
false
exampleplugin_src_main_java_org_acme_example_view_CenterPanePanel.java
1,901
list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { firePropertyChange(SelectionProvider.SELECTION_CHANGED_PROP, null, getSelectedManifestations()); } });
false
exampleplugin_src_main_java_org_acme_example_view_CenterPanePanel.java
1,902
private static class CenterPaneListModel extends AbstractListModel { private final AbstractComponent component; public CenterPaneListModel(AbstractComponent aComponent) { component = aComponent; } @Override public Object getElementAt(int index) { return component.getComponents().get(index).getDisplayName(); } @Override public int getSize() { return component.getComponents().size(); } }
false
exampleplugin_src_main_java_org_acme_example_view_CenterPanePanel.java
1,903
@SuppressWarnings("serial") /** * The <code>PrivateInfoViewRole</code> class provides a view exposed in the inspector area, which is * the right hand side of a window. This view provides information only when the example component is * <em>private</em>. When an <code>AbstractComponent</code> is created, its default visibility is * <em>private</em>. An <code>AbstractComponent</code> becomes <em>public</em> when it is dropped to * a dropbox. * * @author [email protected] */ public final class PrivateInfoView extends View { public PrivateInfoView(AbstractComponent comp, ViewInfo vi) { super(comp,vi); JPanel view = new JPanel(); view.setLayout(new BoxLayout(view, BoxLayout.Y_AXIS)); // Add the header for this view manifestation. view.add(createHeaderRow("Information available only for the owner", Color.red, 15)); //NOI18N view.add(new JLabel()); // Add the content for this view manifestation. AbstractComponent component = getManifestedComponent(); view.add(createMultiLabelRow("Display name of this component: ", component.getDisplayName())); //NOI18N view.add(createMultiLabelRow("Owner of this component: ", component.getOwner())); //NOI18N setLayout(new BorderLayout()); add(view, BorderLayout.NORTH); } // The following are the utility methods for formatting this // info view manifestation. // Creates a formatted JPanel that contains the header in a JLabel private JPanel createHeaderRow(String title, Color color, float size) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(title); label.setFont(label.getFont().deriveFont(Font.BOLD, size)); label.setForeground(color); panel.add(label, BorderLayout.WEST); return panel; } // Creates a formatted JPanel that contains two JLabels: // the field name and the field value. private JPanel createMultiLabelRow(String fieldName, String text) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel field = new JLabel(fieldName); field.setFont(field.getFont().deriveFont(Font.BOLD)); JLabel value = new JLabel(text); value.setFont(field.getFont().deriveFont(Font.BOLD)); value.setForeground(Color.gray); panel.add(field, BorderLayout.WEST); panel.add(value, BorderLayout.CENTER); panel.setBounds(new Rectangle(field.getWidth() + value.getWidth(), 10)); return panel; } }
false
exampleplugin_src_main_java_org_acme_example_view_PrivateInfoView.java
1,904
@SuppressWarnings("serial") public final class PublicInfoView extends View { public PublicInfoView(AbstractComponent ac, ViewInfo vi) { super(ac,vi); JPanel view = new JPanel(); view.setLayout(new BoxLayout(view, BoxLayout.Y_AXIS)); // Add the header for this view manifestation. view.add(createHeaderRow("Information available for everyone", Color.blue, 15)); //NOI18N view.add(new JLabel()); // Add the content for this view manifestation. AbstractComponent component = getManifestedComponent(); view.add(createMultiLabelRow("Display name of this component: ", component.getDisplayName())); //NOI18N view.add(createMultiLabelRow("Owner of this component: ", component.getOwner())); //NOI18N setLayout(new BorderLayout()); add(view, BorderLayout.NORTH); } // The following are the utility methods for formatting this // info view manifestation. // Creates a formatted JPanel that contains the header in a JLabel private JPanel createHeaderRow(String title, Color color, float size) { JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel(title); label.setFont(label.getFont().deriveFont(Font.BOLD, size)); label.setForeground(color); panel.add(label, BorderLayout.WEST); return panel; } // Creates a formatted JPanel that contains two JLabels: // the field name and the field value. private JPanel createMultiLabelRow(String fieldName, String text) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel field = new JLabel(fieldName); field.setFont(field.getFont().deriveFont(Font.BOLD)); JLabel value = new JLabel(text); value.setFont(field.getFont().deriveFont(Font.BOLD)); value.setForeground(Color.gray); panel.add(field, BorderLayout.WEST); panel.add(value, BorderLayout.CENTER); panel.setBounds(new Rectangle(field.getWidth() + value.getWidth(), 10)); return panel; } }
false
exampleplugin_src_main_java_org_acme_example_view_PublicInfoView.java
1,905
@SuppressWarnings("serial") public final class SaveModelStateView extends View { // use a resource bundle for strings to enable localization in the future if required private static ResourceBundle bundle = ResourceBundle.getBundle("ExampleResourceBundle"); private JFormattedTextField doubleDataTextField; private JTextField descriptionTextField; // get this component and its associated model role private ExampleModelRole mr = ExampleComponent.class.cast(getManifestedComponent()).getModel(); // create the GUI public SaveModelStateView(AbstractComponent ac, ViewInfo vi) { super(ac,vi); // This GUI allows a user to modify the component's data and persist it. TitledBorder titledBorder = BorderFactory.createTitledBorder(bundle.getString("ModelBorderTitle")); final JPanel jp = new JPanel(); jp.setBorder(titledBorder); descriptionTextField = new JTextField(); descriptionTextField.setText(mr.getData().getDataDescription()); descriptionTextField.setToolTipText(bundle.getString("DescriptionToolTip")); doubleDataTextField = new JFormattedTextField(NumberFormat.getInstance()); doubleDataTextField.setValue(mr.getData().getDoubleData()); doubleDataTextField.setToolTipText(bundle.getString("ValueToolTip")); // ensure the value is really a double before allowing the focus to change doubleDataTextField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField inputField = (JTextField) input; try { Double.parseDouble(inputField.getText()); } catch (NumberFormatException e) { return false; } return true; } }); JButton saveButton = new JButton(bundle.getString("SaveButton")); jp.add(descriptionTextField); jp.add(doubleDataTextField); addToLayout(jp, bundle.getString("Description"), descriptionTextField, bundle.getString("Value"), doubleDataTextField, saveButton); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AbstractComponent component = getManifestedComponent(); // Update the model from the GUI input. mr.getData().setDoubleData(Double.parseDouble(doubleDataTextField.getText())); mr.getData().setDataDescription(descriptionTextField.getText()); // Save the component component.save(); } }); add(jp); } /** * Configure the grid bag layout that is not really relevant for demonstrating * MCT API usage. **/ private void addToLayout(Container c, String topLabelString, JTextField topField, String bottomLabelString, JTextField bottomField, JButton button) { GridBagLayout gbl = new GridBagLayout(); c.setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.anchor = GridBagConstraints.EAST; gbc.weightx = 0; gbc.weighty = 0; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets(5, 5, 0, 0); JLabel topLabel = new JLabel(topLabelString); topLabel.setLabelFor(topField); JLabel bottomLabel = new JLabel(bottomLabelString); bottomLabel.setLabelFor(bottomField); c.add(topLabel, gbc); gbc.gridy = 1; c.add(bottomLabel, gbc); gbc.gridy = 2; gbc.gridx = 1; gbc.weighty = 1; gbc.anchor = GridBagConstraints.NORTHEAST; gbc.insets = new Insets(5, 5, 0, 5); c.add(button, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.weighty = 0; gbc.weightx = 1; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.WEST; gbc.insets = new Insets(5, 0, 0, 5); c.add(topField, gbc); gbc.gridy = 1; c.add(bottomField, gbc); } // This method is a callback from BaseComponent refreshViewManifestations(). // Its job is to refresh all the GUI manifestations of this view role. In the case of updating the model, // the refresh is done by copying new data from the model to the GUI visual elements. // In our example, the visual elements are a text field and a double value field. @Override public void updateMonitoredGUI() { ExampleModelRole mr = ExampleComponent.class.cast(getManifestedComponent()).getModel(); doubleDataTextField.setValue(mr.getData().getDoubleData()); descriptionTextField.setText(mr.getData().getDataDescription()); } }
false
exampleplugin_src_main_java_org_acme_example_view_SaveModelStateView.java
1,906
doubleDataTextField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField inputField = (JTextField) input; try { Double.parseDouble(inputField.getText()); } catch (NumberFormatException e) { return false; } return true; } });
false
exampleplugin_src_main_java_org_acme_example_view_SaveModelStateView.java
1,907
saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { AbstractComponent component = getManifestedComponent(); // Update the model from the GUI input. mr.getData().setDoubleData(Double.parseDouble(doubleDataTextField.getText())); mr.getData().setDataDescription(descriptionTextField.getText()); // Save the component component.save(); } });
false
exampleplugin_src_main_java_org_acme_example_view_SaveModelStateView.java
1,908
public class ShowChildrenInTableView extends FeedView { private static final long serialVersionUID = 5541863528199833270L; private static final String MAX_TABLE_ROW = "MAX_TABLE_ROW"; private ExampleTableModel tableModel; private ControlPanel controlPanel; public ShowChildrenInTableView(AbstractComponent ac, ViewInfo vi) { super(ac,vi); setLayout(new BorderLayout()); // Get the number of rows to be displayed from the view properties. String maxTableRowStr = getViewProperties().getProperty(MAX_TABLE_ROW, String.class); int maxTableRow = 3; if (maxTableRowStr != null) { maxTableRow = Integer.parseInt(maxTableRowStr); } tableModel = new ExampleTableModel(maxTableRow); JTable table = new JTable(tableModel); controlPanel = new ControlPanel(tableModel, maxTableRow); add(controlPanel, BorderLayout.NORTH); JScrollPane pane = new JScrollPane(table); add(pane, BorderLayout.CENTER); } @Override public Collection<FeedProvider> getVisibleFeedProviders() { // this implementation could have been optimized to build the initial // list of // components in the constructor and then use the // updateMonitoredGUI(AddChildEvent) // and updateMonitoredGUI(RemoveChildEvent) to change the list saving // the iterations // during each rendering cycle List<FeedProvider> feeds = new ArrayList<FeedProvider>( getManifestedComponent().getComponents().size()); for (AbstractComponent childComp : getManifestedComponent().getComponents()) { FeedProvider fp = getFeedProvider(childComp); if (fp != null) { feeds.add(fp); } } return feeds; } @Override public void synchronizeTime(Map<String, List<Map<String, String>>> data, long syncTime) { updateFromFeed(data); } // this method is called during the feed rendering cycle to update the table // based on // new feed data. This method will always be called on the AWT thread, while // the request // will be done off the AWT thread so this method is intended to be // efficient @Override public void updateFromFeed(Map<String, List<Map<String, String>>> data) { // show only one data point if (!data.isEmpty()) { tableModel.setFeedData(data); tableModel.refresh(); } } /** * This method will refresh the manifestation when the number of children to * be displayed is changed. */ @Override public void updateMonitoredGUI() { String maxTableRowStr = getViewProperties().getProperty(MAX_TABLE_ROW, String.class); if (maxTableRowStr != null) { controlPanel.update(Integer.parseInt(maxTableRowStr)); } } /** * Refresh the table model in response to the change in children */ @Override public void updateMonitoredGUI(AddChildEvent event) { tableModel.refresh(); } /** * Refresh the table model in response to the change in children */ @Override public void updateMonitoredGUI(RemoveChildEvent event) { tableModel.refresh(); } /** * Refresh the table model in response to the change in children, this could * be caused by a aborted change */ @Override public void updateMonitoredGUI(ReloadEvent event) { tableModel.refresh(); } @Override public void enterLockedState() { controlPanel.enableEdit(); } @Override public void exitLockedState() { controlPanel.disableEdit(); } /** * This inner class provides a panel which allows a user to specify the * number of children to be displayed in the table of a particular * component. * */ private final class ControlPanel extends JPanel { private static final long serialVersionUID = 6117168640139158850L; private JLabel noOfRowsLabel = new JLabel("Num of Rows to display:"); private JLabel displayNoOfRowsLabel; private JTextField editNoOfRowField; private String maxTableRowStr; private ExampleTableModel tableModel; public ControlPanel(final ExampleTableModel tableModel, int maxTableRow) { setLayout(new BorderLayout()); this.tableModel = tableModel; this.maxTableRowStr = String.valueOf(maxTableRow); displayNoOfRowsLabel = new JLabel(maxTableRowStr); editNoOfRowField = new JTextField(maxTableRowStr); editNoOfRowField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { String currentText = editNoOfRowField.getText().trim(); if (maxTableRowStr == null || !maxTableRowStr.equals(currentText)) { maxTableRowStr = currentText; tableModel.setMaxRowAndSave(Integer .parseInt(currentText)); } } @Override public void focusGained(FocusEvent e) { } }); add(noOfRowsLabel, BorderLayout.WEST); add(editNoOfRowField, BorderLayout.CENTER); } public void update(int maxTableRow) { String newMaxTableRowStr = String.valueOf(maxTableRow); if (!this.maxTableRowStr.equals(newMaxTableRowStr)) { displayNoOfRowsLabel.setText(newMaxTableRowStr); editNoOfRowField.setText(newMaxTableRowStr); this.maxTableRowStr = newMaxTableRowStr; tableModel.setMaxRow(maxTableRow); } } public void enableEdit() { remove(displayNoOfRowsLabel); add(editNoOfRowField, BorderLayout.CENTER); } public void disableEdit() { String newMaxTableRowStr = getViewProperties().getProperty( MAX_TABLE_ROW, String.class); if (newMaxTableRowStr != null) { editNoOfRowField.setText(newMaxTableRowStr); displayNoOfRowsLabel.setText(newMaxTableRowStr); } if (!maxTableRowStr.equals(newMaxTableRowStr) && newMaxTableRowStr != null) { this.maxTableRowStr = newMaxTableRowStr; tableModel.setMaxRow(Integer.parseInt(maxTableRowStr)); } remove(editNoOfRowField); add(displayNoOfRowsLabel, BorderLayout.CENTER); } } /** * A simple table model for the table. * */ private class ExampleTableModel extends AbstractTableModel { private static final long serialVersionUID = 866084276868380575L; private String[] columnNames = { "Component id", "Display Name", "Component Type", "Feed Data"}; private Object[][] data; private int maxRow; private Map<String, List<Map<String, String>>> feedData = Collections .<String, List<Map<String, String>>> emptyMap(); public ExampleTableModel(int maxRow) { this.maxRow = maxRow; populateData(); } private void populateData() { AbstractComponent parentComp = getManifestedComponent(); int numOfChildren = 0; boolean hasChildren = !parentComp.getComponents().isEmpty(); if (hasChildren) { numOfChildren = maxRow < parentComp.getComponents().size() ? maxRow : parentComp.getComponents().size(); } data = new Object[numOfChildren][columnNames.length]; if (numOfChildren > 0) { Iterator<AbstractComponent> children = parentComp.getComponents().iterator(); for (int i = 0; i < numOfChildren; i++) { AbstractComponent childComp = children.next(); data[i][0] = childComp.getId(); data[i][1] = childComp.getDisplayName(); data[i][2] = childComp.getClass().getName(); FeedProvider fp = childComp.getCapability(FeedProvider.class); List<Map<String, String>> feedVal = fp == null ? null : feedData.get(fp.getSubscriptionId()); if (feedVal != null && !feedVal.isEmpty()) { Map<String, String> valMap = feedVal.get(0); String feedData = valMap.get(FeedProvider.NORMALIZED_VALUE_KEY); data[i][3] = feedData == null ? "" : feedData; } else { data[i][3] = ""; } } } } @Override public int getColumnCount() { return columnNames.length; } @Override public int getRowCount() { return data.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return data[rowIndex][columnIndex]; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public String getColumnName(int column) { return columnNames[column]; } public void setFeedData(Map<String, List<Map<String, String>>> feedData) { this.feedData = feedData; } public void refresh() { populateData(); fireTableStructureChanged(); } public void setMaxRow(int maxRow) { if (this.maxRow != maxRow) { this.maxRow = maxRow; refresh(); } } /** * Set the maximum number of rows to be displayed and persist the * MAX_TABLE_ROW view property to the database. * * @param maxRow * The maximum number of rows to be displayed */ public void setMaxRowAndSave(int maxRow) { if (this.maxRow != maxRow) { setMaxRow(maxRow); getViewProperties().setProperty(MAX_TABLE_ROW, String.valueOf(maxRow)); getManifestedComponent().save(); } } } }
false
exampleplugin_src_main_java_org_acme_example_view_ShowChildrenInTableView.java
1,909
private final class ControlPanel extends JPanel { private static final long serialVersionUID = 6117168640139158850L; private JLabel noOfRowsLabel = new JLabel("Num of Rows to display:"); private JLabel displayNoOfRowsLabel; private JTextField editNoOfRowField; private String maxTableRowStr; private ExampleTableModel tableModel; public ControlPanel(final ExampleTableModel tableModel, int maxTableRow) { setLayout(new BorderLayout()); this.tableModel = tableModel; this.maxTableRowStr = String.valueOf(maxTableRow); displayNoOfRowsLabel = new JLabel(maxTableRowStr); editNoOfRowField = new JTextField(maxTableRowStr); editNoOfRowField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { String currentText = editNoOfRowField.getText().trim(); if (maxTableRowStr == null || !maxTableRowStr.equals(currentText)) { maxTableRowStr = currentText; tableModel.setMaxRowAndSave(Integer .parseInt(currentText)); } } @Override public void focusGained(FocusEvent e) { } }); add(noOfRowsLabel, BorderLayout.WEST); add(editNoOfRowField, BorderLayout.CENTER); } public void update(int maxTableRow) { String newMaxTableRowStr = String.valueOf(maxTableRow); if (!this.maxTableRowStr.equals(newMaxTableRowStr)) { displayNoOfRowsLabel.setText(newMaxTableRowStr); editNoOfRowField.setText(newMaxTableRowStr); this.maxTableRowStr = newMaxTableRowStr; tableModel.setMaxRow(maxTableRow); } } public void enableEdit() { remove(displayNoOfRowsLabel); add(editNoOfRowField, BorderLayout.CENTER); } public void disableEdit() { String newMaxTableRowStr = getViewProperties().getProperty( MAX_TABLE_ROW, String.class); if (newMaxTableRowStr != null) { editNoOfRowField.setText(newMaxTableRowStr); displayNoOfRowsLabel.setText(newMaxTableRowStr); } if (!maxTableRowStr.equals(newMaxTableRowStr) && newMaxTableRowStr != null) { this.maxTableRowStr = newMaxTableRowStr; tableModel.setMaxRow(Integer.parseInt(maxTableRowStr)); } remove(editNoOfRowField); add(displayNoOfRowsLabel, BorderLayout.CENTER); } }
false
exampleplugin_src_main_java_org_acme_example_view_ShowChildrenInTableView.java
1,910
editNoOfRowField.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { String currentText = editNoOfRowField.getText().trim(); if (maxTableRowStr == null || !maxTableRowStr.equals(currentText)) { maxTableRowStr = currentText; tableModel.setMaxRowAndSave(Integer .parseInt(currentText)); } } @Override public void focusGained(FocusEvent e) { } });
false
exampleplugin_src_main_java_org_acme_example_view_ShowChildrenInTableView.java
1,911
private class ExampleTableModel extends AbstractTableModel { private static final long serialVersionUID = 866084276868380575L; private String[] columnNames = { "Component id", "Display Name", "Component Type", "Feed Data"}; private Object[][] data; private int maxRow; private Map<String, List<Map<String, String>>> feedData = Collections .<String, List<Map<String, String>>> emptyMap(); public ExampleTableModel(int maxRow) { this.maxRow = maxRow; populateData(); } private void populateData() { AbstractComponent parentComp = getManifestedComponent(); int numOfChildren = 0; boolean hasChildren = !parentComp.getComponents().isEmpty(); if (hasChildren) { numOfChildren = maxRow < parentComp.getComponents().size() ? maxRow : parentComp.getComponents().size(); } data = new Object[numOfChildren][columnNames.length]; if (numOfChildren > 0) { Iterator<AbstractComponent> children = parentComp.getComponents().iterator(); for (int i = 0; i < numOfChildren; i++) { AbstractComponent childComp = children.next(); data[i][0] = childComp.getId(); data[i][1] = childComp.getDisplayName(); data[i][2] = childComp.getClass().getName(); FeedProvider fp = childComp.getCapability(FeedProvider.class); List<Map<String, String>> feedVal = fp == null ? null : feedData.get(fp.getSubscriptionId()); if (feedVal != null && !feedVal.isEmpty()) { Map<String, String> valMap = feedVal.get(0); String feedData = valMap.get(FeedProvider.NORMALIZED_VALUE_KEY); data[i][3] = feedData == null ? "" : feedData; } else { data[i][3] = ""; } } } } @Override public int getColumnCount() { return columnNames.length; } @Override public int getRowCount() { return data.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return data[rowIndex][columnIndex]; } @Override public Class<?> getColumnClass(int columnIndex) { return String.class; } @Override public String getColumnName(int column) { return columnNames[column]; } public void setFeedData(Map<String, List<Map<String, String>>> feedData) { this.feedData = feedData; } public void refresh() { populateData(); fireTableStructureChanged(); } public void setMaxRow(int maxRow) { if (this.maxRow != maxRow) { this.maxRow = maxRow; refresh(); } } /** * Set the maximum number of rows to be displayed and persist the * MAX_TABLE_ROW view property to the database. * * @param maxRow * The maximum number of rows to be displayed */ public void setMaxRowAndSave(int maxRow) { if (this.maxRow != maxRow) { setMaxRow(maxRow); getViewProperties().setProperty(MAX_TABLE_ROW, String.valueOf(maxRow)); getManifestedComponent().save(); } } }
false
exampleplugin_src_main_java_org_acme_example_view_ShowChildrenInTableView.java
1,912
public abstract class Axis extends JComponent { private static final long serialVersionUID = 1L; /** Start value. */ private double start; /** End value. */ private double end; /** Length of major tick marks. */ private int majorTickLength = 10; /** Length of minor tick marks. */ private int minorTickLength = 5; /** Distance between the axis and text labels. */ private int textMargin = 15; /** Whether or not to display labels. */ private boolean showLabels = true; /** * Returns the start value. * @return the start value */ public double getStart() { return start; } /** * Sets the start value. * @param start the start value */ public void setStart(double start) { if(start != this.start) { this.start = start; revalidate(); repaint(); } } /** * Returns the end value. * @return the end value */ public double getEnd() { return end; } /** * Sets the end value. * @param end the end value */ public void setEnd(double end) { if(end != this.end) { this.end = end; revalidate(); repaint(); } } /** * Adds <code>offset</code> to both the start and end. May be more efficient than setting them separately. * @param offset amount to shift the axis */ public void shift(double offset) { if(offset != 0) { end += offset; start += offset; revalidate(); repaint(); } } /** * Returns the length of major tick marks. * @return the length of major tick marks */ public int getMajorTickLength() { return majorTickLength; } /** * Sets the length of major tick marks. * @param majorTickLength the length of major tick marks */ public void setMajorTickLength(int majorTickLength) { this.majorTickLength = majorTickLength; } /** * Returns the length of minor tick marks. * @return the length of minor tick marks */ public int getMinorTickLength() { return minorTickLength; } /** * Sets the length of minor tick marks. * @param minorTickLength the length of minor tick marks */ public void setMinorTickLength(int minorTickLength) { this.minorTickLength = minorTickLength; } /** * Returns the distance between the axis and text labels. * @return the distance between the axis and text labels */ public int getTextMargin() { return textMargin; } /** * Sets the distance between the axis and text labels. * @param textMargin the distance between the axis and text labels */ public void setTextMargin(int textMargin) { this.textMargin = textMargin; } /** * Returns true if this axis displays labels. * @return true if this axis displays labels */ public boolean isShowLabels() { return showLabels; } /** * Sets whether or not this axis should display labels. * @param showLabels true to display labels */ public void setShowLabels(boolean showLabels) { this.showLabels = showLabels; } }
false
Plotter_src_main_java_plotter_Axis.java
1,913
public class AxisLabel extends JLabel { private static final long serialVersionUID = 1L; /** Value to display. */ private double value; /** * Creates a label. * @param value value to display * @param text text version of the value to display */ public AxisLabel(double value, String text) { super(text); this.value = value; } /** * Returns the label's value. * @return the label's value */ public double getValue() { return value; } }
false
Plotter_src_main_java_plotter_AxisLabel.java
1,914
public class CountingGraphics extends GraphicsProxy { private final CountingGraphics root; private List<Line2D> lines = new ArrayList<Line2D>(); private int points; private int simpleLines; private int polyLines; private int shapes; /** * Creates a counting graphics context. * @param base graphics context to forward painting operations to */ public CountingGraphics(Graphics2D base) { super(base); this.root = this; } private CountingGraphics(Graphics2D base, CountingGraphics root) { super(base); this.root = root; } @Override public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { super.drawPolyline(xPoints, yPoints, nPoints); root.points += nPoints; root.polyLines++; AffineTransform transform = base.getTransform(); for(int i = 1; i < nPoints; i++) { Point2D p1 = transform.transform(new Point2D.Double(xPoints[i - 1], yPoints[i - 1]), null); Point2D p2 = transform.transform(new Point2D.Double(xPoints[i], yPoints[i]), null); root.lines.add(new Line2D.Double(p1, p2)); } } @Override public void drawLine(int x1, int y1, int x2, int y2) { super.drawLine(x1, y1, x2, y2); root.points += 2; root.simpleLines++; AffineTransform transform = base.getTransform(); Point2D p1 = transform.transform(new Point2D.Double(x1, y1), null); Point2D p2 = transform.transform(new Point2D.Double(x2, y2), null); root.lines.add(new Line2D.Double(p1, p2)); } @Override public void draw(Shape s) { super.draw(s); root.shapes++; PathIterator pi = s.getPathIterator(base.getTransform(), 0.5); float[] points = new float[6]; Point2D p1 = null; Point2D cp = null; while(!pi.isDone()) { switch(pi.currentSegment(points)) { case PathIterator.SEG_MOVETO: { root.points++; double x1 = Math.floor(points[0]); double y1 = Math.floor(points[1]); p1 = new Point2D.Double(x1, y1); cp = p1; break; } case PathIterator.SEG_LINETO: { root.points++; double x2 = Math.floor(points[0]); double y2 = Math.floor(points[1]); Point2D p2 = new Point2D.Double(x2, y2); root.lines.add(new Line2D.Double(p1, p2)); p1 = p2; break; } case PathIterator.SEG_CLOSE: { root.points++; root.lines.add(new Line2D.Double(p1, cp)); p1 = cp; break; } } pi.next(); } } @Override public Graphics create() { return new CountingGraphics((Graphics2D) base.create(), root); } @Override public Graphics create(int x, int y, int width, int height) { return new CountingGraphics((Graphics2D) base.create(x, y, width, height), root); } /** * Returns the line segments that were drawn. * This includes calls to {@link #drawLine(int, int, int, int)} and {@link #drawPolyline(int[], int[], int)}. * With polylines, each individual line segment is added separately. * @return the line segments that were drawn */ public List<Line2D> getLines() { return lines; } /** * Returns the total point count. * This is increased by 2 for each call to {@link #drawLine(int, int, int, int)}, and by <code>n</code> for each call to {@link #drawPolyline(int[], int[], int)}, * where <code>n</code> is the last parameter. * @return number of points */ public int getPointCount() { return points; } /** * Returns the number of calls to {@link #draw(Shape)}. * @return number of {@link Shape}s drawn */ public int getShapeCount() { return shapes; } }
false
Plotter_src_test_java_plotter_CountingGraphics.java
1,915
public interface Dataset { /** * Returns the size of the dataset. * @return the size of the dataset */ public int getPointCount(); /** * Removes all points from this dataset. */ public void removeAllPoints(); }
false
Plotter_src_main_java_plotter_Dataset.java
1,916
public class DateNumberFormat extends NumberFormat { private static final long serialVersionUID = 1L; private final DateFormat format; /** * Creates a number format based on <code>format</code> * @param format date format to view as a number format */ public DateNumberFormat(DateFormat format) { this.format = format; } @Override public Number parse(String source, ParsePosition parsePosition) { return format.parse(source, parsePosition).getTime(); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { toAppendTo.append(format.format(new Date(number))); return toAppendTo; } @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { toAppendTo.append(format.format(new Date((long) number))); return toAppendTo; } /** * Returns the base format. * @return the base format */ public DateFormat getBaseFormat() { return format; } }
false
Plotter_src_main_java_plotter_DateNumberFormat.java
1,917
public class DoubleData implements Cloneable { /** Default initial capacity. */ private static final int DEFAULT_CAPACITY = 8; /** Contains the data. */ private double[] data; /** Offset within 'data' where usable data starts. */ private int offset; /** Number of elements in the buffer. */ private int length; /** * Creates a buffer with the specified capacity. * @param capacity capacity of the buffer */ public DoubleData(int capacity) { data = new double[capacity]; } /** * Creates a buffer with default capacity. */ public DoubleData() { this(DEFAULT_CAPACITY); } /** * Returns the number of elements in the buffer. * @return the number of elements in the buffer. */ public int getLength() { return length; } /** * Adds an element to the buffer. * @param d element to add */ public void add(double d) { if(length == data.length) { // If we don't have enough space, allocate a larger array setCapacity(data.length * 2); } data[(offset + length) % data.length] = d; length++; } /** * Adds elements to the buffer. * @param d data to add * @param off offset within <code>d</code> to start copying from * @param len number of elements to copy */ public void add(double[] d, int off, int len) { if(off < 0 || len < 0 || off + len > d.length) { throw new IndexOutOfBoundsException("d.length = " + d.length + ", off = " + off + ", len = " + len); } if(length + len > data.length) { // If we don't have enough space, allocate a larger array int newlen = data.length; while(newlen < length + len) { newlen *= 2; } setCapacity(newlen); } int start1 = (offset + length) % data.length; int end1 = Math.min(start1 + len, data.length); System.arraycopy(d, off, data, start1, end1 - start1); if(end1 - start1 < len) { System.arraycopy(d, off + end1 - start1, data, 0, len - end1 + start1); } length += len; } /** * Adds elements to the buffer. * @param d data to add * @param off offset within <code>d</code> to start copying from * @param len number of elements to copy */ public void add(DoubleData d, int off, int len) { if(off < 0 || len < 0 || off + len > d.length) { throw new IndexOutOfBoundsException("d.getLength() = " + d.length + ", off = " + off + ", len = " + len); } int off2 = (d.offset + off) % d.data.length; int available = d.data.length - off2; if(available < len) { add(d.data, off2, available); add(d.data, 0, len - available); } else { add(d.data, off2, len); } } /** * Copies data from the source object. * @param src object to copy data from * @param srcoff index within src to copy data from * @param dstoff index within this to copy data to * @param len number of elements to copy */ public void copyFrom(DoubleData src, int srcoff, int dstoff, int len) { if(srcoff < 0 || len < 0 || srcoff + len > src.length) { throw new IndexOutOfBoundsException("src.getLength() = " + src.length + ", srcoff = " + srcoff + ", len = " + len); } if(dstoff < 0 || dstoff + len > length) { throw new IndexOutOfBoundsException("dstoff = " + dstoff + ", len = " + len + ", getLength() = " + length); } int off2 = (src.offset + srcoff) % src.data.length; int available = src.data.length - off2; if(available < len) { // Which order depends only if src == data. int dstoff2 = (dstoff + offset) % data.length; if(dstoff2 < off2 && dstoff2 > (src.offset + srcoff + len) % src.data.length) { copyFrom(src.data, off2, dstoff, available); copyFrom(src.data, 0, dstoff + available, len - available); } else { copyFrom(src.data, 0, dstoff + available, len - available); copyFrom(src.data, off2, dstoff, available); } } else { copyFrom(src.data, off2, dstoff, len); } } /** * Copies data from the source object. * @param src object to copy data from * @param srcoff index within src to copy data from * @param dstoff index within this to copy data to * @param len number of elements to copy */ public void copyFrom(double[] src, int srcoff, int dstoff, int len) { if(srcoff < 0 || len < 0 || srcoff + len > src.length) { throw new IndexOutOfBoundsException("d.length = " + src.length + ", srcoff = " + srcoff + ", len = " + len); } if(dstoff < 0 || dstoff + len > length) { throw new IndexOutOfBoundsException("dstoff = " + dstoff + ", len = " + len + ", getLength() = " + length); } int off2 = (offset + dstoff) % data.length; int available = data.length - off2; if(available < len) { // Which order depends only if src == data. if(off2 < srcoff + len) { System.arraycopy(src, srcoff + available, data, 0, len - available); System.arraycopy(src, srcoff, data, off2, available); } else { System.arraycopy(src, srcoff, data, off2, available); System.arraycopy(src, srcoff + available, data, 0, len - available); } } else { System.arraycopy(src, srcoff, data, off2, len); } } /** * Inserts a value into the buffer. * @param index position for the new value * @param d value to add */ public void insert(int index, double d) { if(index < 0 || index > length) { throw new IndexOutOfBoundsException("Index out of bounds: " + index + ", length is " + length); } if(length == data.length) { setCapacity(data.length * 2); } // TODO: See if this mess can be simplified int split = data.length - offset; if(index < length / 2) { // Insert near head; shift early elements left if(index <= split) { if(offset == 0) { data[data.length - 1] = data[0]; System.arraycopy(data, offset + 1, data, offset, index); } else { System.arraycopy(data, offset, data, offset - 1, index); } } else { System.arraycopy(data, offset, data, offset - 1, split); data[data.length - 1] = data[0]; System.arraycopy(data, 1, data, 0, index - split - 1); } offset = (offset + data.length - 1) % data.length; } else { // Insert near tail; shift late elements right if(index < split) { if(split <= length) { System.arraycopy(data, 0, data, 1, length - split); data[0] = data[data.length - 1]; System.arraycopy(data, index + offset, data, index + offset + 1, split - index - 1); } else { System.arraycopy(data, index + offset, data, index + offset + 1, length - index); } } else { System.arraycopy(data, index - split, data, index - split + 1, length - index); } } length++; data[(offset + index) % data.length] = d; } /** * Inserts elements into the buffer. * @param index position for the new value * @param d data to add * @param off offset within d to start copying data from * @param len number of elements to insert */ public void insert(int index, DoubleData d, int off, int len) { if(index < 0 || index > length) { throw new IndexOutOfBoundsException("Index out of bounds: " + index + ", length is " + length); } if(off < 0 || len < 0 || off + len > d.length) { throw new IndexOutOfBoundsException("Index out of bounds: off = " + off + ", len = " + len + ", d.length = " + d.length); } int newlen = length + len; int cap = data.length; while(newlen > cap) { cap *= 2; } if(cap != data.length) { setCapacity(cap); } if(index < length / 2) { // Insert near head; shift early elements left length += len; offset = (offset + data.length - len) % data.length; // implicitly shifts elements right copyFrom(this, len, 0, index); } else { // Insert near tail; shift late elements right length += len; copyFrom(this, index, index + len, getLength() - index - len); } copyFrom(d, off, index, len); } /** * Adds elements to the beginning of the buffer. * @param d data to add * @param off offset within <code>d</code> to start copying from * @param len number of elements to add */ public void prepend(double[] d, int off, int len) { if(len < 0 || off < 0 || off + len > d.length) { throw new IndexOutOfBoundsException("d.length = " + d.length + ", off = " + off + ", len = " + len); } if(length + len > data.length) { int newlen = data.length; while(newlen < length + len) { newlen *= 2; } setCapacity(newlen); } int start1 = (offset - len + data.length) % data.length; int end1 = Math.min(start1 + len, data.length); System.arraycopy(d, off, data, start1, end1 - start1); if(end1 - start1 < len) { System.arraycopy(d, off + end1 - start1, data, 0, len - end1 + start1); } length += len; offset = (offset - len + data.length) % data.length; } /** * Adds elements to the beginning of the buffer. * @param d data to add * @param off offset within <code>d</code> to start copying from * @param len number of elements to add */ public void prepend(DoubleData d, int off, int len) { if(len < 0 || off < 0 || off + len > d.length) { throw new IndexOutOfBoundsException("d.getLength() = " + d.length + ", off = " + off + ", len = " + len); } int off2 = (d.offset + off) % d.data.length; int available = d.data.length - off2; if(available < len) { prepend(d.data, 0, len - available); prepend(d.data, off2, available); } else { prepend(d.data, off2, len); } } /** * Returns the element at the given index. * @param index index of the element * @return value at that index */ public double get(int index) { if(index < 0 || index >= length) { throw new IndexOutOfBoundsException("Index out of bounds: " + index + ", length is " + length); } return data[(offset + index) % data.length]; } /** * Sets the element at the given index * @param index index of the element * @param d value to set at that index */ public void set(int index, double d) { if(index < 0 || index >= length) { throw new IndexOutOfBoundsException("Index out of bounds: " + index + ", length is " + length); } data[(offset + index) % data.length] = d; } /** * Returns the capacity, or the maximum length the buffer can grow to without resizing. * @return the capacity */ public int getCapacity() { return data.length; } /** * Sets the buffer's capacity. * The new capacity cannot be less than the amount of data currently in the buffer. * @param capacity new capacity * @throws IllegalArgumentException if the requested capacity is less than the length */ public void setCapacity(int capacity) { if(capacity < length) { throw new IllegalArgumentException("Cannot set capacity less than the current length. Remove elements first. length = " + length + ", new capacity = " + capacity); } if(capacity == data.length) { return; } double[] data2 = new double[capacity]; int available = data.length - offset; if(length <= available) { System.arraycopy(data, offset, data2, 0, length); } else { System.arraycopy(data, offset, data2, 0, available); System.arraycopy(data, 0, data2, available, length - available); } data = data2; offset = 0; } /** * Removes elements from the front of the buffer. * @param count number of elements to remove */ public void removeFirst(int count) { if(count < 0) { throw new IllegalArgumentException("Count cannot be negative: " + count); } if(count > length) { throw new IllegalArgumentException("Trying to remove " + count + " elements, but only contains " + length); } offset = (offset + count) % data.length; length -= count; } /** * Removes elements from the end of the buffer. * @param count number of elements to remove */ public void removeLast(int count) { if(count < 0) { throw new IllegalArgumentException("Count cannot be negative: " + count); } if(count > length) { throw new IllegalArgumentException("Trying to remove " + count + " elements, but only contains " + length); } length -= count; } /** * Searches the data for an insertion point. * Assumes the data is sorted. * Assumes the data does not contain NaNs and that the argument is not NaN. * Runs in O(log(n)) time, where n is the length (as defined by {@link #getLength()}). * @param d value to search for * @return index of the search key, if it is contained in the array; otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. * The <i>insertion point</i> is defined as the point at which the key would be inserted into the array: * the index of the first element greater than the key, or <tt>a.length</tt> if all elements in the array are less than the specified key. * Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found. */ public int binarySearch(double d) { if(length == 0) { return -1; } int min = 0; int max = length; while(max - min > 1) { int mid = (min + max) / 2; double x = data[(offset + mid) % data.length]; if(x < d) { min = mid; } else if(x > d) { max = mid; } else { // assume x==d return mid; } } double x = data[(offset + min) % data.length]; if(x == d) { return min; } else if(x < d) { return -min - 2; } else { return -min - 1; } } /** * Searches the data for an insertion point. * Assumes the data is sorted. * Assumes the data does not contain NaNs and that the argument is not NaN. * Runs on average in O(log(log(n))) time, where n is the length (as defined by {@link #getLength()}). * However, in the worst case (where the values are exponentially distributed), may run in O(n) time. * @param d value to search for * @return index of the search key, if it is contained in the array; otherwise, <tt>(-(<i>insertion point</i>) - 1)</tt>. * The <i>insertion point</i> is defined as the point at which the key would be inserted into the array: * the index of the first element greater than the key, or <tt>a.length</tt> if all elements in the array are less than the specified key. * Note that this guarantees that the return value will be &gt;= 0 if and only if the key is found. */ public int dictionarySearch(double d) { if(length == 0) { return -1; } int min = 0; int max = length - 1; while(true) { double minval = get(min); if(minval > d) { return -min - 1; } double maxval = get(max); if(maxval < d) { return -max - 2; } int mid = min + (int) ((d - minval) * (max - min) / (maxval - minval)); double midval = get(mid); if(midval < d) { min = mid + 1; } else if(midval > d) { max = mid - 1; } else { return mid; } } } /** * Removes everything from the buffer. */ public void removeAll() { length = 0; } @Override public DoubleData clone() { try { DoubleData d = (DoubleData) super.clone(); d.data = data.clone(); return d; } catch(CloneNotSupportedException e) { throw new RuntimeException(e); // should never happen } } }
false
Plotter_src_main_java_plotter_DoubleData.java
1,918
public class DoubleDiffer { /** Allowable difference between doubles. */ double error; /** * Creates a {@link DoubleDiffer} with the given tolerance * @param error maximum allowable difference between doubles */ public DoubleDiffer(double error) { this.error = error; } /** * Asserts that the absolute value of the difference between the doubles is less than the tolerance. * @param expected expected value * @param actual actual value * @throws AssertionFailedError if the doubles are farther apart than the tolerance allows */ public void assertClose(double expected, double actual) { Assert.assertTrue("Expected: " + expected + ", actual: " + actual, Math.abs(expected - actual) < error); } }
false
Plotter_src_test_java_plotter_DoubleDiffer.java
1,919
public class ExpFormat extends NumberFormat { private static final long serialVersionUID = 1L; /** Does the actual formatting. */ private NumberFormat baseFormat; /** * Creates a log format. * @param baseFormat used to do the actual formatting */ public ExpFormat(NumberFormat baseFormat) { this.baseFormat = baseFormat; } @Override public Number parse(String source, ParsePosition parsePosition) { return Math.log10(baseFormat.parse(source, parsePosition).doubleValue()); } @Override public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) { return baseFormat.format(Math.pow(10, number), toAppendTo, pos); } @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return baseFormat.format(Math.pow(10, number), toAppendTo, pos); } /** * Returns the base format. * @return the base format */ public NumberFormat getBaseFormat() { return baseFormat; } }
false
Plotter_src_main_java_plotter_ExpFormat.java
1,920
public class GraphicsProxy extends Graphics2D { /** The delegate that all painting calls are forwarded to. */ protected final Graphics2D base; /** * Creates a graphics proxy. * @param base base graphics object, a.k.a. the delegate */ public GraphicsProxy(Graphics2D base) { this.base = base; } public void addRenderingHints(Map<?, ?> hints) { base.addRenderingHints(hints); } public void clearRect(int x, int y, int width, int height) { base.clearRect(x, y, width, height); } public void clip(Shape s) { base.clip(s); } public void clipRect(int x, int y, int width, int height) { base.clipRect(x, y, width, height); } public void copyArea(int x, int y, int width, int height, int dx, int dy) { base.copyArea(x, y, width, height, dx, dy); } public void draw(Shape s) { base.draw(s); } public void draw3DRect(int x, int y, int width, int height, boolean raised) { base.draw3DRect(x, y, width, height, raised); } public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { base.drawArc(x, y, width, height, startAngle, arcAngle); } public void drawBytes(byte[] data, int offset, int length, int x, int y) { base.drawBytes(data, offset, length, x, y); } public void drawChars(char[] data, int offset, int length, int x, int y) { base.drawChars(data, offset, length, x, y); } public void drawGlyphVector(GlyphVector g, float x, float y) { base.drawGlyphVector(g, x, y); } public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) { base.drawImage(img, op, x, y); } public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) { return base.drawImage(img, xform, obs); } public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { return base.drawImage(img, x, y, bgcolor, observer); } public boolean drawImage(Image img, int x, int y, ImageObserver observer) { return base.drawImage(img, x, y, observer); } public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) { return base.drawImage(img, x, y, width, height, bgcolor, observer); } public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) { return base.drawImage(img, x, y, width, height, observer); } public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { return base.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) { return base.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, observer); } public void drawLine(int x1, int y1, int x2, int y2) { base.drawLine(x1, y1, x2, y2); } public void drawOval(int x, int y, int width, int height) { base.drawOval(x, y, width, height); } public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) { base.drawPolygon(xPoints, yPoints, nPoints); } public void drawPolygon(Polygon p) { base.drawPolygon(p); } public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) { base.drawPolyline(xPoints, yPoints, nPoints); } public void drawRect(int x, int y, int width, int height) { base.drawRect(x, y, width, height); } public void drawRenderableImage(RenderableImage img, AffineTransform xform) { base.drawRenderableImage(img, xform); } public void drawRenderedImage(RenderedImage img, AffineTransform xform) { base.drawRenderedImage(img, xform); } public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { base.drawRoundRect(x, y, width, height, arcWidth, arcHeight); } public void drawString(AttributedCharacterIterator iterator, float x, float y) { base.drawString(iterator, x, y); } public void drawString(AttributedCharacterIterator iterator, int x, int y) { base.drawString(iterator, x, y); } public void drawString(String str, float x, float y) { base.drawString(str, x, y); } public void drawString(String str, int x, int y) { base.drawString(str, x, y); } public void fill(Shape s) { base.fill(s); } public void fill3DRect(int x, int y, int width, int height, boolean raised) { base.fill3DRect(x, y, width, height, raised); } public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { base.fillArc(x, y, width, height, startAngle, arcAngle); } public void fillOval(int x, int y, int width, int height) { base.fillOval(x, y, width, height); } public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) { base.fillPolygon(xPoints, yPoints, nPoints); } public void fillPolygon(Polygon p) { base.fillPolygon(p); } public void fillRect(int x, int y, int width, int height) { base.fillRect(x, y, width, height); } public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) { base.fillRoundRect(x, y, width, height, arcWidth, arcHeight); } public Color getBackground() { return base.getBackground(); } public Shape getClip() { return base.getClip(); } public Rectangle getClipBounds() { return base.getClipBounds(); } public Rectangle getClipBounds(Rectangle r) { return base.getClipBounds(r); } @Deprecated public Rectangle getClipRect() { return base.getClipRect(); } public Color getColor() { return base.getColor(); } public Composite getComposite() { return base.getComposite(); } public GraphicsConfiguration getDeviceConfiguration() { return base.getDeviceConfiguration(); } public Font getFont() { return base.getFont(); } public FontMetrics getFontMetrics() { return base.getFontMetrics(); } public FontMetrics getFontMetrics(Font f) { return base.getFontMetrics(f); } public FontRenderContext getFontRenderContext() { return base.getFontRenderContext(); } public Paint getPaint() { return base.getPaint(); } public Object getRenderingHint(Key hintKey) { return base.getRenderingHint(hintKey); } public RenderingHints getRenderingHints() { return base.getRenderingHints(); } public Stroke getStroke() { return base.getStroke(); } public AffineTransform getTransform() { return base.getTransform(); } public boolean hit(Rectangle rect, Shape s, boolean onStroke) { return base.hit(rect, s, onStroke); } public boolean hitClip(int x, int y, int width, int height) { return base.hitClip(x, y, width, height); } public void rotate(double theta, double x, double y) { base.rotate(theta, x, y); } public void rotate(double theta) { base.rotate(theta); } public void scale(double sx, double sy) { base.scale(sx, sy); } public void setBackground(Color color) { base.setBackground(color); } public void setClip(int x, int y, int width, int height) { base.setClip(x, y, width, height); } public void setClip(Shape clip) { base.setClip(clip); } public void setColor(Color c) { base.setColor(c); } public void setComposite(Composite comp) { base.setComposite(comp); } public void setFont(Font font) { base.setFont(font); } public void setPaint(Paint paint) { base.setPaint(paint); } public void setPaintMode() { base.setPaintMode(); } public void setRenderingHint(Key hintKey, Object hintValue) { base.setRenderingHint(hintKey, hintValue); } public void setRenderingHints(Map<?, ?> hints) { base.setRenderingHints(hints); } public void setStroke(Stroke s) { base.setStroke(s); } public void setTransform(AffineTransform Tx) { base.setTransform(Tx); } public void setXORMode(Color c1) { base.setXORMode(c1); } public void shear(double shx, double shy) { base.shear(shx, shy); } public void transform(AffineTransform Tx) { base.transform(Tx); } public void translate(double tx, double ty) { base.translate(tx, ty); } public void translate(int x, int y) { base.translate(x, y); } /** * Returns a new GraphicsProxy which wraps the return value of <code>base.create()</code>. * @return new proxy graphics object */ @Override public Graphics create() { return new GraphicsProxy((Graphics2D) base.create()); } /** * Returns a new GraphicsProxy which wraps the return value of <code>base.create(x, y, width, height)</code>. * @return new proxy graphics object */ @Override public Graphics create(int x, int y, int width, int height) { return new GraphicsProxy((Graphics2D) base.create(x, y, width, height)); } @Override public void dispose() { base.dispose(); } }
false
Plotter_src_test_java_plotter_GraphicsProxy.java
1,921
public class IntegerTickMarkCalculator implements TickMarkCalculator { private static final double[] EMPTY = new double[0]; @Override public double[][] calculateTickMarks(Axis axis) { double axisStart = axis.getStart(); double axisEnd = axis.getEnd(); double min; double max; if(axisStart < axisEnd) { min = axisStart; max = axisEnd; } else { min = axisEnd; max = axisStart; } int start = (int) Math.ceil(min); int end = (int) Math.floor(max); int count = end - start + 1; double[] majorVals; if(count > 0) { majorVals = new double[count]; for(int i = 0; i < count; i++) { majorVals[i] = start + i; } } else { majorVals = EMPTY; } return new double[][] { majorVals, EMPTY }; } }
false
Plotter_src_main_java_plotter_IntegerTickMarkCalculator.java
1,922
public class JUnitAll extends TestSuite { public static TestSuite suite() { TestSuite suite = new TestSuite("Plotter"); suite.addTestSuite(JUnitDateNumberFormat.class); suite.addTestSuite(JUnitDoubleData.class); suite.addTestSuite(JUnitExpFormat.class); suite.addTestSuite(JUnitIntegerTickMarkCalculator.class); suite.addTestSuite(JUnitLinearTickMarkCalculator.class); suite.addTestSuite(JUnitLogTickMarkCalculator.class); suite.addTestSuite(JUnitTimeTickMarkCalculator.class); suite.addTest(JUnitInternal.suite()); suite.addTest(JUnitXY.suite()); return suite; } }
false
Plotter_src_test_java_plotter_JUnitAll.java
1,923
public class JUnitDateNumberFormat extends TestCase { public void testFormat() { DateFormat baseFormat = new SimpleDateFormat("yyyy-MM-dd"); baseFormat.setTimeZone(TimeZone.getTimeZone("GMT")); DateNumberFormat format = new DateNumberFormat(baseFormat); assertEquals("1970-01-01", format.format(0L)); assertEquals("2001-09-09", format.format(1000000000000L)); assertEquals("1970-01-01", format.format(0.0)); assertEquals("2001-09-09", format.format(1000000000000.0)); assertSame(baseFormat, format.getBaseFormat()); } public void testParse() throws ParseException { DateFormat baseFormat = new SimpleDateFormat("yyyy-MM-dd"); baseFormat.setTimeZone(TimeZone.getTimeZone("GMT")); DateNumberFormat format = new DateNumberFormat(baseFormat); assertEquals(946684800000L, format.parse("2000-01-01")); assertEquals(1317340800000L, format.parse("2011-09-30")); } }
false
Plotter_src_test_java_plotter_JUnitDateNumberFormat.java
1,924
public class JUnitDoubleData extends TestCase { public void testGrow() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(1); assertEquals(2, data.getLength()); data.add(2); assertEquals(3, data.getLength()); data.add(3); assertEquals(4, data.getLength()); data.add(4); assertEquals(5, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(1.0, data.get(1)); assertEquals(2.0, data.get(2)); assertEquals(3.0, data.get(3)); assertEquals(4.0, data.get(4)); } public void testCycle() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(1); assertEquals(2, data.getLength()); data.add(2); assertEquals(3, data.getLength()); data.add(3); assertEquals(4, data.getLength()); data.removeFirst(1); assertEquals(3, data.getLength()); data.add(4); assertEquals(4, data.getLength()); assertEquals(1.0, data.get(0)); assertEquals(2.0, data.get(1)); assertEquals(3.0, data.get(2)); assertEquals(4.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testAddMultiple() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(new double[] {2, 3, 4}, 0, 3); assertEquals(4, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(2.0, data.get(1)); assertEquals(3.0, data.get(2)); assertEquals(4.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testAddHuge() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); double[] d = new double[100]; for(int i = 0; i < d.length; i++) { d[i] = i + 1; } data.add(d, 0, d.length); assertEquals(1 + d.length, data.getLength()); for(int i = 0; i < d.length + 1; i++) { assertEquals((double) i, data.get(i)); } assertEquals(128, data.getCapacity()); } public void testAddOutOfRange() { DoubleData data = new DoubleData(); double[] d = new double[10]; try { data.add(d, -1, 1); fail("Should have thrown an IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } try { data.add(d, 10, 1); fail("Should have thrown an IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } try { data.add(d, 5, 6); fail("Should have thrown an IndexOutOfBoundsException"); } catch(IndexOutOfBoundsException e) { } // should all work data.add(d, 0, 1); data.add(d, 9, 1); data.add(d, 5, 5); } public void testAddDoubleData() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); DoubleData data2 = new DoubleData(); data2.add(new double[] { 2, 3, 4 }, 0, 3); data.add(data2, 0, 3); assertEquals(4, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(2.0, data.get(1)); assertEquals(3.0, data.get(2)); assertEquals(4.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testAddDoubleData2() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); DoubleData data2 = new DoubleData(); data2.add(new double[] { 2, 3, 4 }, 0, 3); data.add(data2, 1, 2); assertEquals(3, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(3.0, data.get(1)); assertEquals(4.0, data.get(2)); assertEquals(4, data.getCapacity()); } public void testAddDoubleDataWithCycle() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); DoubleData data2 = new DoubleData(4); data2.add(1); data2.add(2); data2.add(3); data2.removeFirst(2); data2.add(4); data2.add(5); assertEquals(3, data2.getLength()); data.add(data2, 0, 3); assertEquals(4, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(3.0, data.get(1)); assertEquals(4.0, data.get(2)); assertEquals(5.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testAddDoubleDataOutOfRange() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); DoubleData data2 = new DoubleData(); data2.add(new double[] { 2, 3, 4 }, 0, 3); try { data.add(data2, 1, 3); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.add(data2, -1, 1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.add(data2, 1, -1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } // should work data.add(data2, 0, 3); data.add(data2, 1, 2); } public void testAddMultipleWithCycle() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(1); assertEquals(2, data.getLength()); data.removeFirst(1); assertEquals(1, data.getLength()); data.add(new double[] {2, 3, 4}, 0, 3); assertEquals(4, data.getLength()); assertEquals(1.0, data.get(0)); assertEquals(2.0, data.get(1)); assertEquals(3.0, data.get(2)); assertEquals(4.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testPrependMultiple() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.prepend(new double[] {2, 3, 4}, 0, 3); assertEquals(4, data.getLength()); assertEquals(2.0, data.get(0)); assertEquals(3.0, data.get(1)); assertEquals(4.0, data.get(2)); assertEquals(0.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testPrependMultipleWithCycle() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(1); assertEquals(2, data.getLength()); data.removeFirst(1); assertEquals(1, data.getLength()); data.prepend(new double[] {2, 3, 4}, 0, 3); assertEquals(4, data.getLength()); assertEquals(2.0, data.get(0)); assertEquals(3.0, data.get(1)); assertEquals(4.0, data.get(2)); assertEquals(1.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testPrependMultipleWithCycle2() { DoubleData data = new DoubleData(4); data.add(0); assertEquals(1, data.getLength()); data.add(1); assertEquals(2, data.getLength()); data.removeFirst(1); assertEquals(1, data.getLength()); DoubleData data2 = new DoubleData(4); data2.add(0); data2.add(1); data2.add(2); data2.add(3); data2.removeFirst(2); data2.add(4); assertEquals(3, data2.getLength()); assertEquals(4, data2.getCapacity()); data.prepend(data2, 0, 3); assertEquals(4, data.getLength()); assertEquals(2.0, data.get(0)); assertEquals(3.0, data.get(1)); assertEquals(4.0, data.get(2)); assertEquals(1.0, data.get(3)); assertEquals(4, data.getCapacity()); } public void testPrependOutOfRange() { DoubleData data = new DoubleData(4); data.add(0); double[] d = new double[] { 2, 3, 4 }; try { data.prepend(d, -1, 1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); try { data.prepend(d, 0, -1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); try { data.prepend(d, 1, 3); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); // should work data.prepend(d, 1, 2); } public void testPrependDoubleDataOutOfRange() { DoubleData data = new DoubleData(4); data.add(0); DoubleData d = new DoubleData(); d.add(2); d.add(3); d.add(4); try { data.prepend(d, -1, 1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); try { data.prepend(d, 0, -1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); try { data.prepend(d, 1, 3); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(1, data.getLength()); // should work data.prepend(d, 1, 2); } public void testBinarySearch() { testBinarySearch(new double[] {}, .5, -1); testBinarySearch(new double[] {1}, .5, -1); testBinarySearch(new double[] {1}, 1, 0); testBinarySearch(new double[] {1}, 1.5, -2); testBinarySearch(new double[] {1, 2}, .5, -1); testBinarySearch(new double[] {1, 2}, 1, 0); testBinarySearch(new double[] {1, 2}, 1.5, -2); testBinarySearch(new double[] {1, 2}, 2, 1); testBinarySearch(new double[] {1, 2}, 2.5, -3); testBinarySearch(new double[] {1, 2, 3}, .5, -1); testBinarySearch(new double[] {1, 2, 3}, 1, 0); testBinarySearch(new double[] {1, 2, 3}, 1.5, -2); testBinarySearch(new double[] {1, 2, 3}, 2, 1); testBinarySearch(new double[] {1, 2, 3}, 2.5, -3); testBinarySearch(new double[] {1, 2, 3}, 3, 2); testBinarySearch(new double[] {1, 2, 3}, 3.5, -4); } private void testBinarySearch(double[] values, double d, int index) { DoubleData data = new DoubleData(4); data.add(values, 0, values.length); assertEquals(index, data.binarySearch(d)); } public void testDictionarySearch() { testDictionarySearch(new double[] {}, .5, -1); testDictionarySearch(new double[] {1}, .5, -1); testDictionarySearch(new double[] {1}, 1, 0); testDictionarySearch(new double[] {1}, 1.5, -2); testDictionarySearch(new double[] {1, 2}, .5, -1); testDictionarySearch(new double[] {1, 2}, 1, 0); testDictionarySearch(new double[] {1, 2}, 1.5, -2); testDictionarySearch(new double[] {1, 2}, 2, 1); testDictionarySearch(new double[] {1, 2}, 2.5, -3); testDictionarySearch(new double[] {1, 2, 3}, .5, -1); testDictionarySearch(new double[] {1, 2, 3}, 1, 0); testDictionarySearch(new double[] {1, 2, 3}, 1.5, -2); testDictionarySearch(new double[] {1, 2, 3}, 2, 1); testDictionarySearch(new double[] {1, 2, 3}, 2.5, -3); testDictionarySearch(new double[] {1, 2, 3}, 3, 2); testDictionarySearch(new double[] {1, 2, 3}, 3.5, -4); testDictionarySearch(new double[] {1, 2, 3, 4}, .5, -1); testDictionarySearch(new double[] {1, 2, 3, 4}, 1, 0); testDictionarySearch(new double[] {1, 2, 3, 4}, 1.5, -2); testDictionarySearch(new double[] {1, 2, 3, 4}, 2, 1); testDictionarySearch(new double[] {1, 2, 3, 4}, 2.5, -3); testDictionarySearch(new double[] {1, 2, 3, 4}, 3, 2); testDictionarySearch(new double[] {1, 2, 3, 4}, 3.5, -4); testDictionarySearch(new double[] {1, 2, 3, 4}, 4, 3); testDictionarySearch(new double[] {1, 2, 3, 4}, 4.5, -5); } private void testDictionarySearch(double[] values, double d, int index) { DoubleData data = new DoubleData(4); data.add(values, 0, values.length); assertEquals(index, data.dictionarySearch(d)); } public void testInsertCloseToHead() { for(int pad = 0; pad < 8; pad++) { DoubleData data = new DoubleData(8); for(int i = 0; i < pad; i++) { data.add(-1); } data.removeFirst(pad); data.add(7); data.add(8); data.add(9); data.add(10); data.add(11); data.add(12); assertEquals(6, data.getLength()); data.insert(2, 8.5); assertEquals(7, data.getLength()); assertEquals(7.0, data.get(0)); assertEquals(8.0, data.get(1)); assertEquals(8.5, data.get(2)); assertEquals(9.0, data.get(3)); assertEquals(10.0, data.get(4)); assertEquals(11.0, data.get(5)); assertEquals(12.0, data.get(6)); } } public void testInsertCloseToTail() { for(int pad = 0; pad < 8; pad++) { DoubleData data = new DoubleData(8); for(int i = 0; i < pad; i++) { data.add(-1); } data.removeFirst(pad); data.add(5); data.add(6); data.add(7); data.add(8); data.add(9); data.add(10); assertEquals(6, data.getLength()); data.insert(5, 9.5); assertEquals(7, data.getLength()); assertEquals(5.0, data.get(0)); assertEquals(6.0, data.get(1)); assertEquals(7.0, data.get(2)); assertEquals(8.0, data.get(3)); assertEquals(9.0, data.get(4)); assertEquals(9.5, data.get(5)); assertEquals(10.0, data.get(6)); } } public void testInsertGrow() { DoubleData data = new DoubleData(4); for(int i = 0; i < 4; i++) { data.add(i); } data.insert(1, 5); assertEquals(5, data.getLength()); assertEquals(8, data.getCapacity()); assertEquals(0.0, data.get(0)); assertEquals(5.0, data.get(1)); assertEquals(1.0, data.get(2)); assertEquals(2.0, data.get(3)); assertEquals(3.0, data.get(4)); } public void testInsertOutOfRange() { DoubleData data = new DoubleData(4); for(int i = 0; i < 4; i++) { data.add(i); } try { data.insert(-1, 0); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); try { data.insert(5, 0); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); // should work data.insert(4, 0); } public void testInsertDoubleData() { DoubleData data = new DoubleData(4); DoubleData data2 = new DoubleData(4); for(int i = 0; i < 4; i++) { data.add(i); data2.add(i + 4); } data.insert(1, data2, 1, 3); assertEquals(7, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(5.0, data.get(1)); assertEquals(6.0, data.get(2)); assertEquals(7.0, data.get(3)); assertEquals(1.0, data.get(4)); assertEquals(2.0, data.get(5)); assertEquals(3.0, data.get(6)); } public void testInsertDoubleDataNearTail() { DoubleData data = new DoubleData(4); DoubleData data2 = new DoubleData(4); for(int i = 0; i < 4; i++) { data.add(i); data2.add(i + 4); } data.insert(3, data2, 1, 3); assertEquals(7, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(1.0, data.get(1)); assertEquals(2.0, data.get(2)); assertEquals(5.0, data.get(3)); assertEquals(6.0, data.get(4)); assertEquals(7.0, data.get(5)); assertEquals(3.0, data.get(6)); } public void testInsertDoubleDataOutOfRange() { DoubleData data = new DoubleData(4); DoubleData data2 = new DoubleData(4); for(int i = 0; i < 4; i++) { data.add(i); data2.add(i + 4); } try { data.insert(-1, data2, 0, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); try { data.insert(0, data2, -1, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); try { data.insert(0, data2, 2, 3); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); try { data.insert(5, data2, 0, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } assertEquals(4, data.getLength()); // should work data.insert(4, data2, 0, 1); } public void testCopyFrom() { DoubleData data = new DoubleData(8); for(int i = 0; i < 4; i++) { data.add(i); } assertEquals(4, data.getLength()); double[] d = new double[] {5, 6, 7, 8}; data.copyFrom(d, 1, 1, 2); assertEquals(4, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(6.0, data.get(1)); assertEquals(7.0, data.get(2)); assertEquals(3.0, data.get(3)); } public void testCopyFromWithCycle() { DoubleData data = new DoubleData(8); for(int i = 0; i < 8; i++) { data.add(i); } data.removeFirst(4); data.add(8); data.add(9); data.add(10); data.add(11); assertEquals(8, data.getLength()); double[] d = new double[] {13, 14, 15, 16, 17, 18, 19, 20, 21}; data.copyFrom(d, 2, 1, 5); assertEquals(8, data.getLength()); assertEquals(4.0, data.get(0)); assertEquals(15.0, data.get(1)); assertEquals(16.0, data.get(2)); assertEquals(17.0, data.get(3)); assertEquals(18.0, data.get(4)); assertEquals(19.0, data.get(5)); assertEquals(10.0, data.get(6)); assertEquals(11.0, data.get(7)); } public void testCopyFromOutOfRange() { DoubleData data = new DoubleData(8); for(int i = 0; i < 4; i++) { data.add(i); } assertEquals(4, data.getLength()); double[] d = new double[] { 5, 6, 7, 8 }; try { data.copyFrom(d, 0, 0, -1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(d, -1, 0, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(d, 0, -1, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(d, 2, 0, 3); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(d, 0, 2, 3); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } // should work data.copyFrom(d, 2, 0, 2); data.copyFrom(d, 0, 2, 2); data.copyFrom(d, 0, 0, 1); } private DoubleData init(int cap, int off, int len) { DoubleData data = new DoubleData(cap); for(int i = 0; i < off; i++) { data.add(0); } data.removeFirst(off); for(int i = 0; i < len; i++) { data.add(i); } return data; } private void assertRange(DoubleData data, int off, int len, int start) { for(int i = 0; i < len; i++) { assertEquals((double)start + i, data.get(off + i)); } } // () = src // [] = dest // ' = offset // | = array ends // | ' [] () | public void testCopyFromSelf0() { DoubleData data = init(100, 0, 90); data.copyFrom(data, 70, 10, 5); assertRange(data, 0, 10, 0); assertRange(data, 10, 5, 70); assertRange(data, 15, 75, 15); } // | [] ' () | public void testCopyFromSelf1() { DoubleData data = init(100, 50, 90); data.copyFrom(data, 20, 60, 5); assertRange(data, 0, 60, 0); assertRange(data, 60, 5, 20); assertRange(data, 65, 15, 65); } // | [] () ' | public void testCopyFromSelf2() { DoubleData data = init(100, 90, 90); data.copyFrom(data, 70, 0, 5); assertRange(data, 0, 5, 70); assertRange(data, 5, 85, 5); } // | ' [ ( ] ) | public void testCopyFromSelf3() { DoubleData data = init(100, 1, 90); data.copyFrom(data, 12, 10, 5); assertRange(data, 0, 10, 0); assertRange(data, 10, 5, 12); assertRange(data, 15, 75, 15); } // | [ ( ] ) ' | public void testCopyFromSelf4() { DoubleData data = init(100, 90, 90); data.copyFrom(data, 22, 20, 5); assertRange(data, 0, 20, 0); assertRange(data, 20, 5, 22); assertRange(data, 25, 65, 25); } // | ' ( [ ) ] | public void testCopyFromSelf5() { DoubleData data = init(100, 1, 90); data.copyFrom(data, 20, 22, 5); assertRange(data, 0, 22, 0); assertRange(data, 22, 5, 20); assertRange(data, 27, 63, 27); } // | ( [ ) ] ' | public void testCopyFromSelf6() { DoubleData data = init(100, 90, 90); data.copyFrom(data, 20, 22, 5); assertRange(data, 0, 22, 0); assertRange(data, 22, 5, 20); assertRange(data, 27, 63, 27); } // | ' () [] | public void testCopyFromSelf7() { DoubleData data = init(100, 1, 90); data.copyFrom(data, 20, 40, 5); assertRange(data, 0, 40, 0); assertRange(data, 40, 5, 20); assertRange(data, 45, 45, 45); } // | () ' [] | public void testCopyFromSelf8() { DoubleData data = init(100, 50, 90); data.copyFrom(data, 70, 20, 5); assertRange(data, 0, 20, 0); assertRange(data, 20, 5, 70); assertRange(data, 25, 65, 25); } // | () [] ' | public void testCopyFromSelf9() { DoubleData data = init(100, 90, 90); data.copyFrom(data, 20, 70, 5); assertRange(data, 0, 70, 0); assertRange(data, 70, 5, 20); assertRange(data, 75, 15, 75); } // | ] ' () [ | public void testCopyFromSelf10() { DoubleData data = init(100, 30, 90); data.copyFrom(data, 10, 68, 5); assertRange(data, 0, 68, 0); assertRange(data, 68, 5, 10); assertRange(data, 73, 17, 73); } // | ] () ' [ | public void testCopyFromSelf11() { DoubleData data = init(100, 80, 90); data.copyFrom(data, 70, 18, 5); assertRange(data, 0, 18, 0); assertRange(data, 18, 5, 70); assertRange(data, 23, 67, 23); } // | ] ' ( [ ) | public void testCopyFromSelf12() { DoubleData data = init(100, 30, 90); data.copyFrom(data, 64, 67, 5); assertRange(data, 0, 67, 0); assertRange(data, 67, 5, 64); assertRange(data, 72, 18, 72); } // | ( ] ) ' [ | public void testCopyFromSelf13() { DoubleData data = init(100, 80, 90); data.copyFrom(data, 21, 18, 5); assertRange(data, 0, 18, 0); assertRange(data, 18, 5, 21); assertRange(data, 23, 67, 23); } // | [ ) ] ' ( | public void testCopyFromSelf14() { DoubleData data = init(100, 80, 90); data.copyFrom(data, 18, 21, 5); assertRange(data, 0, 21, 0); assertRange(data, 21, 5, 18); assertRange(data, 26, 64, 26); } // | ) ' [] ( | public void testCopyFromSelf15() { DoubleData data = init(100, 30, 90); data.copyFrom(data, 68, 10, 5); assertRange(data, 0, 10, 0); assertRange(data, 10, 5, 68); assertRange(data, 15, 75, 15); } // | ) [] ' ( | public void testCopyFromSelf16() { DoubleData data = init(100, 80, 90); data.copyFrom(data, 18, 70, 5); assertRange(data, 0, 70, 0); assertRange(data, 70, 5, 18); assertRange(data, 75, 15, 75); } // | ) ' [ ( ] | public void testCopyFromSelf17() { DoubleData data = init(100, 30, 90); data.copyFrom(data, 67, 64, 5); assertRange(data, 0, 64, 0); assertRange(data, 64, 5, 67); assertRange(data, 69, 11, 69); } // | ] ) ' [ ( | public void testCopyFromSelf18() { DoubleData data = init(100, 60, 90); data.copyFrom(data, 38, 37, 5); assertRange(data, 0, 37, 0); assertRange(data, 37, 5, 38); assertRange(data, 42, 48, 42); } // | ) ] ' ( [ | public void testCopyFromSelf19() { DoubleData data = init(100, 60, 90); data.copyFrom(data, 37, 38, 5); assertRange(data, 0, 38, 0); assertRange(data, 38, 5, 37); assertRange(data, 43, 47, 43); } public void testCopyFromDoubleData() { DoubleData data = new DoubleData(8); DoubleData data2 = new DoubleData(8); for(int i = 0; i < 8; i++) { data.add(i); data2.add(i + 8); } data.copyFrom(data2, 1, 2, 4); assertEquals(8, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(1.0, data.get(1)); assertEquals(9.0, data.get(2)); assertEquals(10.0, data.get(3)); assertEquals(11.0, data.get(4)); assertEquals(12.0, data.get(5)); assertEquals(6.0, data.get(6)); assertEquals(7.0, data.get(7)); } public void testCopyFromDoubleDataWithCycle() { DoubleData data = new DoubleData(8); DoubleData data2 = new DoubleData(8); for(int i = 0; i < 8; i++) { data.add(i); data2.add(i + 8); } data2.removeFirst(4); for(int i = 0; i < 4; i++) { data2.add(i + 20); } data.copyFrom(data2, 1, 2, 4); assertEquals(8, data.getLength()); assertEquals(0.0, data.get(0)); assertEquals(1.0, data.get(1)); assertEquals(13.0, data.get(2)); assertEquals(14.0, data.get(3)); assertEquals(15.0, data.get(4)); assertEquals(20.0, data.get(5)); assertEquals(6.0, data.get(6)); assertEquals(7.0, data.get(7)); } public void testCopyFromDoubleDataOutOfRange() { DoubleData data = new DoubleData(8); DoubleData data2 = new DoubleData(8); for(int i = 0; i < 8; i++) { data.add(i); data2.add(i + 8); } try { data.copyFrom(data2, -1, 0, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(data2, 0, -1, 1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(data2, 6, 0, 3); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(data2, 0, 6, 3); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { data.copyFrom(data2, 0, 0, -1); fail("Should throw an exception"); } catch(IndexOutOfBoundsException e) { // should happen } // should work data.copyFrom(data2, 0, 0, 1); data.copyFrom(data2, 6, 0, 2); data.copyFrom(data2, 0, 6, 2); } public void testClone() { DoubleData d = init(8, 1, 3); DoubleData d2 = d.clone(); assertRange(d2, 0, d2.getLength(), 0); d.set(0, 1); d.add(-1); assertRange(d2, 0, d2.getLength(), 0); } public void testGetOutOfRange() { DoubleData d = init(8, 1, 4); try { d.get(-1); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { d.get(4); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } // should work d.get(3); } public void testSetOutOfRange() { DoubleData d = init(8, 1, 4); try { d.set(-1, 0); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } try { d.set(4, 0); fail("Should have thrown an exception"); } catch(IndexOutOfBoundsException e) { // should happen } // should work d.set(3, 0); } public void testSetCapacity() { DoubleData d = init(8, 1, 4); assertEquals(8, d.getCapacity()); try { d.setCapacity(-1); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } // Shouldn't be able to shrink it less than the length try { d.setCapacity(3); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } // No change, should do nothing d.setCapacity(8); assertEquals(8, d.getCapacity()); assertEquals(4, d.getLength()); d.setCapacity(16); assertEquals(16, d.getCapacity()); assertEquals(4, d.getLength()); d.setCapacity(4); assertEquals(4, d.getCapacity()); assertEquals(4, d.getLength()); for(int i = 0; i < 4; i++) { assertEquals((double)i, d.get(i)); } } public void testRemoveFirst() { DoubleData data = new DoubleData(); data.add(0); data.add(1); data.add(2); data.removeFirst(1); assertEquals(2, data.getLength()); assertEquals(1.0, data.get(0)); try { data.removeFirst(-1); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } assertEquals(2, data.getLength()); try { data.removeFirst(3); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } assertEquals(2, data.getLength()); data.removeFirst(2); assertEquals(0, data.getLength()); } public void testRemoveLast() { DoubleData data = new DoubleData(); data.add(0); data.add(1); data.add(2); data.removeLast(1); assertEquals(2, data.getLength()); assertEquals(0.0, data.get(0)); try { data.removeLast(-1); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } assertEquals(2, data.getLength()); try { data.removeLast(3); fail("Should have thrown an exception"); } catch(IllegalArgumentException e) { // should happen } assertEquals(2, data.getLength()); data.removeLast(2); assertEquals(0, data.getLength()); } private String dump(DoubleData d) { StringBuffer b = new StringBuffer(); b.append("{"); int n = d.getLength(); for(int i = 0; i < n; i++) { if(i > 0) { b.append(", "); } b.append(d.get(i)); } b.append("}"); return b.toString(); } }
false
Plotter_src_test_java_plotter_JUnitDoubleData.java
1,925
public class JUnitExpFormat extends TestCase { public void testFormat() { DecimalFormat baseFormat = new DecimalFormat("0.0"); ExpFormat format = new ExpFormat(baseFormat); assertEquals("10.0", format.format(1L)); assertEquals("0.1", format.format(-1L)); assertEquals("10.0", format.format(1.0)); assertEquals("0.1", format.format(-1.0)); assertSame(baseFormat, format.getBaseFormat()); } public void testParse() throws ParseException { ExpFormat format = new ExpFormat(new DecimalFormat("0.0")); assertEquals(1.0, format.parse("10.0")); assertEquals(-1.0, format.parse("0.1")); } }
false
Plotter_src_test_java_plotter_JUnitExpFormat.java
1,926
public class JUnitIntegerTickMarkCalculator extends TestCase { public void testExact() { double[][] data = ticks(1, 2); check(data[0], 1.0, 2.0); check(data[1]); } public void testLess() { double[][] data = ticks(1.01, 1.99); check(data[0]); check(data[1]); } public void testMore() { double[][] data = ticks(0.99, 2.01); check(data[0], 1.0, 2.0); check(data[1]); } public void testExactNegative() { double[][] data = ticks(-2, -1); check(data[0], -1.0, -2.0); check(data[1]); } public void testLessNegative() { double[][] data = ticks(-1.99, -1.01); check(data[0]); check(data[1]); } public void testMoreNegative() { double[][] data = ticks(-2.01, -0.99); check(data[0], -1.0, -2.0); check(data[1]); } public void testExactInverted() { double[][] data = ticks(2, 1); check(data[0], 1.0, 2.0); check(data[1]); } public void testLessInverted() { double[][] data = ticks(1.99, 1.01); check(data[0]); check(data[1]); } public void testMoreInverted() { double[][] data = ticks(2.01, 0.99); check(data[0], 1.0, 2.0); check(data[1]); } public void testExactNegativeInverted() { double[][] data = ticks(-1, -2); check(data[0], -1.0, -2.0); check(data[1]); } public void testLessNegativeInverted() { double[][] data = ticks(-1.01, -1.99); check(data[0]); check(data[1]); } public void testMoreNegativeInverted() { double[][] data = ticks(-0.99, -2.01); check(data[0], -1.0, -2.0); check(data[1]); } public void testExactPosNeg() { double[][] data = ticks(-1, 1); check(data[0], -1.0, 0.0, 1.0); check(data[1]); } public void testLessPosNeg() { double[][] data = ticks(-0.99, 0.99); check(data[0], 0.0); check(data[1]); } public void testMorePosNeg() { double[][] data = ticks(-1.01, 1.01); check(data[0], -1.0, 0.0, 1.0); check(data[1]); } public void testExactPosNegInverted() { double[][] data = ticks(1, -1); check(data[0], -1.0, 0.0, 1.0); check(data[1]); } public void testLessPosNegInverted() { double[][] data = ticks(0.99, -0.99); check(data[0], 0.0); check(data[1]); } public void testMorePosNegInverted() { double[][] data = ticks(1.01, -1.01); check(data[0], -1.0, 0.0, 1.0); check(data[1]); } private void check(double[] actual, double... expected) { Arrays.sort(actual); Arrays.sort(expected); String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) < .0000001); } } private double[][] ticks(double start, double end) { IntegerTickMarkCalculator c = new IntegerTickMarkCalculator(); Axis axis = new Axis() { private static final long serialVersionUID = 1L; }; axis.setStart(start); axis.setEnd(end); return c.calculateTickMarks(axis); } }
false
Plotter_src_test_java_plotter_JUnitIntegerTickMarkCalculator.java
1,927
Axis axis = new Axis() { private static final long serialVersionUID = 1L; };
false
Plotter_src_test_java_plotter_JUnitIntegerTickMarkCalculator.java
1,928
public class JUnitLinearTickMarkCalculator extends TestCase { public void testExact() { double[][] data = ticks(1, 2); checkMajor(data[0], 1.0, 1.5, 2.0); check(data[1], 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0); } public void testLess() { double[][] data = ticks(1.01, 1.99); checkMajor(data[0], 1.2, 1.4, 1.6, 1.8); check(data[1], 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9); } public void testMore() { double[][] data = ticks(0.99, 2.01); checkMajor(data[0], 1.0, 1.5, 2.0); check(data[1], 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0); } public void testExactNegative() { double[][] data = ticks(-2, -1); checkMajor(data[0], -2.0, -1.5, -1.0); check(data[1], -1.0, -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9, -2.0); } public void testLessNegative() { double[][] data = ticks(-1.99, -1.01); checkMajor(data[0], -1.8, -1.6, -1.4, -1.2); check(data[1], -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9); } public void testMoreNegative() { double[][] data = ticks(-2.01, -0.99); checkMajor(data[0], -2.0, -1.5, -1.0); check(data[1], -1.0, -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9, -2.0); } public void testExactInverted() { double[][] data = ticks(2, 1); checkMajor(data[0], 1.0, 1.5, 2.0); check(data[1], 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0); } public void testLessInverted() { double[][] data = ticks(1.99, 1.01); checkMajor(data[0], 1.2, 1.4, 1.6, 1.8); check(data[1], 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9); } public void testMoreInverted() { double[][] data = ticks(2.01, 0.99); checkMajor(data[0], 1.0, 1.5, 2.0); check(data[1], 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0); } public void testExactNegativeInverted() { double[][] data = ticks(-1, -2); checkMajor(data[0], -2.0, -1.5, -1.0); check(data[1], -1.0, -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9, -2.0); } public void testLessNegativeInverted() { double[][] data = ticks(-1.01, -1.99); checkMajor(data[0], -1.8, -1.6, -1.4, -1.2); check(data[1], -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9); } public void testMoreNegativeInverted() { double[][] data = ticks(-0.99, -2.01); checkMajor(data[0], -2.0, -1.5, -1.0); check(data[1], -1.0, -1.1, -1.2, -1.3, -1.4, -1.5, -1.6, -1.7, -1.8, -1.9, -2.0); } public void testExactPosNeg() { double[][] data = ticks(-1, 1); checkMajor(data[0], -1.0, 0.0, 1.0); check(data[1], -1, -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1); } public void testLessPosNeg() { double[][] data = ticks(-0.99, 0.99); checkMajor(data[0], -0.5, 0.0, 0.5); check(data[1], -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9); } public void testMorePosNeg() { double[][] data = ticks(-1.01, 1.01); checkMajor(data[0], -1.0, 0.0, 1.0); check(data[1], -1, -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1); } public void testExactPosNegInverted() { double[][] data = ticks(1, -1); checkMajor(data[0], -1.0, 0.0, 1.0); check(data[1], -1, -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1); } public void testLessPosNegInverted() { double[][] data = ticks(0.99, -0.99); checkMajor(data[0], -0.5, 0.0, 0.5); check(data[1], -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9); } public void testMorePosNegInverted() { double[][] data = ticks(1.01, -1.01); checkMajor(data[0], -1.0, 0.0, 1.0); check(data[1], -1, -.9, -.8, -.7, -.6, -.5, -.4, -.3, -.2, -.1, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1); } private void checkMajor(double[] actual, double... expected) { String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) < .0000001); } } private void check(double[] actual, double... expected) { Arrays.sort(actual); Arrays.sort(expected); String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) < .0000001); } } private double[][] ticks(double start, double end) { LinearTickMarkCalculator c = new LinearTickMarkCalculator(); Axis axis = new Axis() { private static final long serialVersionUID = 1L; }; axis.setStart(start); axis.setEnd(end); double[][] data = c.calculateTickMarks(axis); return data; } }
false
Plotter_src_test_java_plotter_JUnitLinearTickMarkCalculator.java
1,929
Axis axis = new Axis() { private static final long serialVersionUID = 1L; };
false
Plotter_src_test_java_plotter_JUnitLinearTickMarkCalculator.java
1,930
public class JUnitLogTickMarkCalculator extends TestCase { public void testExact() { double[][] data = ticks(1, 10); check(data[0], 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); check(data[1], 1.0, 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325, 10.0); } public void testLess() { double[][] data = ticks(1.01, 9.99); check(data[0], 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); check(data[1], 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325); } public void testMore() { double[][] data = ticks(.99, 10.01); check(data[0], 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); check(data[1], 1.0, 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325, 10.0); } public void testExactInverted() { double[][] data = ticks(10, 1); check(data[0], 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); check(data[1], 1.0, 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325, 10.0); } public void testLessInverted() { double[][] data = ticks(9.99, 1.01); check(data[0], 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); check(data[1], 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325); } public void testMoreInverted() { double[][] data = ticks(10.01, .99); check(data[0], 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); check(data[1], 1.0, 1.3010299956639813, 1.4771212547196624, 1.6020599913279625, 1.6989700043360187, 1.7781512503836436, 1.845098040014257, 1.9030899869919435, 1.9542425094393248, 2.0, 2.3010299956639813, 2.4771212547196626, 2.6020599913279625, 2.6989700043360187, 2.778151250383644, 2.845098040014257, 2.9030899869919438, 2.9542425094393248, 3.0, 3.3010299956639813, 3.4771212547196626, 3.6020599913279625, 3.6989700043360187, 3.778151250383644, 3.845098040014257, 3.9030899869919438, 3.9542425094393248, 4.0, 4.301029995663981, 4.477121254719663, 4.6020599913279625, 4.698970004336019, 4.778151250383644, 4.845098040014257, 4.903089986991944, 4.954242509439325, 5.0, 5.301029995663981, 5.477121254719663, 5.6020599913279625, 5.698970004336019, 5.778151250383644, 5.845098040014257, 5.903089986991944, 5.954242509439325, 6.0, 6.301029995663981, 6.477121254719663, 6.6020599913279625, 6.698970004336019, 6.778151250383644, 6.845098040014257, 6.903089986991944, 6.954242509439325, 7.0, 7.301029995663981, 7.477121254719663, 7.6020599913279625, 7.698970004336019, 7.778151250383644, 7.845098040014257, 7.903089986991944, 7.954242509439325, 8.0, 8.301029995663981, 8.477121254719663, 8.602059991327963, 8.698970004336019, 8.778151250383644, 8.845098040014257, 8.903089986991944, 8.954242509439325, 9.0, 9.301029995663981, 9.477121254719663, 9.602059991327963, 9.698970004336019, 9.778151250383644, 9.845098040014257, 9.903089986991944, 9.954242509439325, 10.0); } private void check(double[] actual, double... expected) { Arrays.sort(actual); Arrays.sort(expected); String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) < .0000001); } } private double[][] ticks(double start, double end) { LogTickMarkCalculator c = new LogTickMarkCalculator(); Axis axis = new Axis() { private static final long serialVersionUID = 1L; }; axis.setStart(start); axis.setEnd(end); return c.calculateTickMarks(axis); } }
false
Plotter_src_test_java_plotter_JUnitLogTickMarkCalculator.java
1,931
Axis axis = new Axis() { private static final long serialVersionUID = 1L; };
false
Plotter_src_test_java_plotter_JUnitLogTickMarkCalculator.java
1,932
public class JUnitTimeTickMarkCalculator extends TestCase { private static final long SECOND = 1000; private static final long MINUTE = 60 * SECOND; private static final long HOUR = 60 * MINUTE; private static final long DAY = 24 * HOUR; public void testExact() { double[][] data = ticks(60 * 1000, 120 * 1000); checkMajor(data[0], 60000, 75000, 90000, 105000, 120000); check(data[1], 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000); } public void testLess() { double[][] data = ticks(60 * 1000 + 1, 120 * 1000 - 1); checkMajor(data[0], 75000, 90000, 105000); check(data[1], 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000); } public void testMore() { double[][] data = ticks(60 * 1000 - 1, 120 * 1000 + 1); checkMajor(data[0], 60000, 90000, 120000); check(data[1], 60000, 70000, 80000, 90000, 100000, 110000, 120000); } public void testExactNegative() { double[][] data = ticks(-60 * 1000, -120 * 1000); checkMajor(data[0], -120000, -105000, -90000, -75000, -60000); check(data[1], -60000, -65000, -70000, -75000, -80000, -85000, -90000, -95000, -100000, -105000, -110000, -115000, -120000); } public void testLessNegative() { double[][] data = ticks(-60 * 1000 - 1, -120 * 1000 + 1); checkMajor(data[0], -105000, -90000, -75000); check(data[1], -65000, -70000, -75000, -80000, -85000, -90000, -95000, -100000, -105000, -110000, -115000); } public void testMoreNegative() { double[][] data = ticks(-60 * 1000 + 1, -120 * 1000 - 1); checkMajor(data[0], -120000, -90000, -60000); check(data[1], -60000, -70000, -80000, -90000, -100000, -110000, -120000); } public void testExactInverted() { double[][] data = ticks(120 * 1000, 60 * 1000); checkMajor(data[0], 60000, 75000, 90000, 105000, 120000); check(data[1], 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000); } public void testLessInverted() { double[][] data = ticks(120 * 1000 - 1, 60 * 1000 + 1); checkMajor(data[0], 75000, 90000, 105000); check(data[1], 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000); } public void testMoreInverted() { double[][] data = ticks(120 * 1000 + 1, 60 * 1000 - 1); checkMajor(data[0], 60000, 90000, 120000); check(data[1], 60000, 70000, 80000, 90000, 100000, 110000, 120000); } public void testExactNegativeInverted() { double[][] data = ticks(-120 * 1000, -60 * 1000); checkMajor(data[0], -120000, -105000, -90000, -75000, -60000); check(data[1], -60000, -65000, -70000, -75000, -80000, -85000, -90000, -95000, -100000, -105000, -110000, -115000, -120000); } public void testLessNegativeInverted() { double[][] data = ticks(-120 * 1000 + 1, -60 * 1000 - 1); checkMajor(data[0], -105000, -90000, -75000); check(data[1], -65000, -70000, -75000, -80000, -85000, -90000, -95000, -100000, -105000, -110000, -115000); } public void testMoreNegativeInverted() { double[][] data = ticks(-120 * 1000 - 1, -60 * 1000 + 1); checkMajor(data[0], -120000, -90000, -60000); check(data[1], -60000, -70000, -80000, -90000, -100000, -110000, -120000); } public void testExactPosNeg() { double[][] data = ticks(-60 * 1000, 60 * 1000); checkMajor(data[0], -60000, -30000, 0.0, 30000, 60000); check(data[1], -60000, -50000, -40000, -30000, -20000, -10000, 0.0, 10000, 20000, 30000, 40000, 50000, 60000); } public void testLessPosNeg() { double[][] data = ticks(-60 * 1000 + 1, 60 * 1000 - 1); checkMajor(data[0], -30000, 0.0, 30000); check(data[1], -50000, -40000, -30000, -20000, -10000, 0.0, 10000, 20000, 30000, 40000, 50000); } public void testMorePosNeg() { double[][] data = ticks(-60 * 1000 - 1, 60 * 1000 + 1); checkMajor(data[0], 0.0); check(data[1], -60000, 0.0, 60000); } public void testExactPosNegInverted() { double[][] data = ticks(60 * 1000, -60 * 1000); checkMajor(data[0], -60000, -30000, 0.0, 30000, 60000); check(data[1], -60000, -50000, -40000, -30000, -20000, -10000, 0.0, 10000, 20000, 30000, 40000, 50000, 60000); } public void testLessPosNegInverted() { double[][] data = ticks(60 * 1000 - 1, -60 * 1000 + 1); checkMajor(data[0], -30000, 0.0, 30000); check(data[1], -50000, -40000, -30000, -20000, -10000, 0.0, 10000, 20000, 30000, 40000, 50000); } public void testMorePosNegInverted() { double[][] data = ticks(60 * 1000 + 1, -60 * 1000 - 1); checkMajor(data[0], 0.0); check(data[1], -60000, 0.0, 60000); } public void test11Days() { double[][] data = ticks(0, 11 * DAY); checkMajor(data[0], 0, 5 * DAY, 10 * DAY); check(data[1], 0, 1 * DAY, 2 * DAY, 3 * DAY, 4 * DAY, 5 * DAY, 6 * DAY, 7 * DAY, 8 * DAY, 9 * DAY, 10 * DAY, 11 * DAY); } public void test7Days() { double[][] data = ticks(0, 7 * DAY); checkMajor(data[0], 0, 2 * DAY, 4 * DAY, 6 * DAY); check(data[1], 0, 1 * DAY, 2 * DAY, 3 * DAY, 4 * DAY, 5 * DAY, 6 * DAY, 7 * DAY); } public void test4Days() { double[][] data = ticks(0, 4 * DAY); checkMajor(data[0], 0, 1 * DAY, 2 * DAY, 3 * DAY, 4 * DAY); check(data[1], 0, .5 * DAY, 1 * DAY, 1.5 * DAY, 2 * DAY, 2.5 * DAY, 3 * DAY, 3.5 * DAY, 4 * DAY); } public void test36Hours() { double[][] data = ticks(0, 36 * HOUR); checkMajor(data[0], 0, 12 * HOUR, 24 * HOUR, 36 * HOUR); check(data[1], 0, 6 * HOUR, 12 * HOUR, 18 * HOUR, 24 * HOUR, 30 * HOUR, 36 * HOUR); } public void test18Hours() { double[][] data = ticks(0, 18 * HOUR); checkMajor(data[0], 0, 6 * HOUR, 12 * HOUR, 18 * HOUR); check(data[1], 0, 2 * HOUR, 4 * HOUR, 6 * HOUR, 8 * HOUR, 10 * HOUR, 12 * HOUR, 14 * HOUR, 16 * HOUR, 18 * HOUR); } public void test4Hours() { double[][] data = ticks(0, 4 * HOUR); checkMajor(data[0], 0, 2 * HOUR, 4 * HOUR); check(data[1], 0, 1 * HOUR, 2 * HOUR, 3 * HOUR, 4 * HOUR); } public void test90Minutes() { double[][] data = ticks(0, 90 * MINUTE); checkMajor(data[0], 0, 30 * MINUTE, 60 * MINUTE, 90 * MINUTE); check(data[1], 0, 10 * MINUTE, 20 * MINUTE, 30 * MINUTE, 40 * MINUTE, 50 * MINUTE, 60 * MINUTE, 70 * MINUTE, 80 * MINUTE, 90 * MINUTE); } public void test45Minutes() { double[][] data = ticks(0, 45 * MINUTE); checkMajor(data[0], 0, 15 * MINUTE, 30 * MINUTE, 45 * MINUTE); check(data[1], 0, 5 * MINUTE, 10 * MINUTE, 15 * MINUTE, 20 * MINUTE, 25 * MINUTE, 30 * MINUTE, 35 * MINUTE, 40 * MINUTE, 45 * MINUTE); } public void test25Minutes() { double[][] data = ticks(0, 25 * MINUTE); checkMajor(data[0], 0, 10 * MINUTE, 20 * MINUTE); check(data[1], 0, 5 * MINUTE, 10 * MINUTE, 15 * MINUTE, 20 * MINUTE, 25 * MINUTE); } public void test15Minutes() { double[][] data = ticks(0, 15 * MINUTE); checkMajor(data[0], 0, 5 * MINUTE, 10 * MINUTE, 15 * MINUTE); check(data[1], 0, 1 * MINUTE, 2 * MINUTE, 3 * MINUTE, 4 * MINUTE, 5 * MINUTE, 6 * MINUTE, 7 * MINUTE, 8 * MINUTE, 9 * MINUTE, 10 * MINUTE, 11 * MINUTE, 12 * MINUTE, 13 * MINUTE, 14 * MINUTE, 15 * MINUTE); } public void test5Minutes() { double[][] data = ticks(0, 5 * MINUTE); checkMajor(data[0], 0, 2 * MINUTE, 4 * MINUTE); check(data[1], 0, 1 * MINUTE, 2 * MINUTE, 3 * MINUTE, 4 * MINUTE, 5 * MINUTE); } public void test90Seconds() { double[][] data = ticks(0, 90 * SECOND); checkMajor(data[0], 0, 30 * SECOND, 60 * SECOND, 90 * SECOND); check(data[1], 0, 10 * SECOND, 20 * SECOND, 30 * SECOND, 40 * SECOND, 50 * SECOND, 60 * SECOND, 70 * SECOND, 80 * SECOND, 90 * SECOND); } public void test45Seconds() { double[][] data = ticks(0, 45 * SECOND); checkMajor(data[0], 0, 15 * SECOND, 30 * SECOND, 45 * SECOND); check(data[1], 0, 5 * SECOND, 10 * SECOND, 15 * SECOND, 20 * SECOND, 25 * SECOND, 30 * SECOND, 35 * SECOND, 40 * SECOND, 45 * SECOND); } public void test25Seconds() { double[][] data = ticks(0, 25 * SECOND); checkMajor(data[0], 0, 10 * SECOND, 20 * SECOND); check(data[1], 0, 5 * SECOND, 10 * SECOND, 15 * SECOND, 20 * SECOND, 25 * SECOND); } public void test15Seconds() { double[][] data = ticks(0, 15 * SECOND); checkMajor(data[0], 0, 5 * SECOND, 10 * SECOND, 15 * SECOND); check(data[1], 0, 1 * SECOND, 2 * SECOND, 3 * SECOND, 4 * SECOND, 5 * SECOND, 6 * SECOND, 7 * SECOND, 8 * SECOND, 9 * SECOND, 10 * SECOND, 11 * SECOND, 12 * SECOND, 13 * SECOND, 14 * SECOND, 15 * SECOND); } public void test5Seconds() { double[][] data = ticks(0, 5 * SECOND); checkMajor(data[0], 0, 2 * SECOND, 4 * SECOND); check(data[1], 0, 1 * SECOND, 2 * SECOND, 3 * SECOND, 4 * SECOND, 5 * SECOND); } public void test600Millis() { double[][] data = ticks(0, 600); checkMajor(data[0], 0, 200, 400, 600); check(data[1], 0, 100, 200, 300, 400, 500, 600); } public void test300Millis() { double[][] data = ticks(0, 300); checkMajor(data[0], 0, 100, 200, 300); check(data[1], 0, 50, 100, 150, 200, 250, 300); } public void test100Millis() { double[][] data = ticks(0, 100); checkMajor(data[0], 0, 50, 100); check(data[1], 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100); } private void checkMajor(double[] actual, double... expected) { String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) <= .0000001 * Math.abs(expected[i])); } } private void check(double[] actual, double... expected) { Arrays.sort(actual); Arrays.sort(expected); String msg = "Expected " + Arrays.toString(expected) + ", but got " + Arrays.toString(actual); assertEquals(msg, expected.length, actual.length); for(int i = 0; i < expected.length; i++) { assertTrue(msg, Math.abs(expected[i] - actual[i]) <= .0000001 * Math.abs(expected[i])); } } private double[][] ticks(double start, double end) { TimeTickMarkCalculator c = new TimeTickMarkCalculator(); Axis axis = new Axis() { private static final long serialVersionUID = 1L; }; axis.setStart(start); axis.setEnd(end); double[][] data = c.calculateTickMarks(axis); return data; } }
false
Plotter_src_test_java_plotter_JUnitTimeTickMarkCalculator.java
1,933
Axis axis = new Axis() { private static final long serialVersionUID = 1L; };
false
Plotter_src_test_java_plotter_JUnitTimeTickMarkCalculator.java
1,934
public class LineChecker { /** Maximum allowable distance between two points that count as a match. */ private double error = .00001; /** Required line segments. */ private List<Line2D> required = new ArrayList<Line2D>(); /** Allowed but not required line segments. */ private List<Line2D> allowed = new ArrayList<Line2D>(); /** * Adds a required line segment. * @param x1 X coordinate of end 1 * @param y1 Y coordinate of end 1 * @param x2 X coordinate of end 2 * @param y2 Y coordinate of end 2 */ public void require(double x1, double y1, double x2, double y2) { required.add(new Line2D.Double(x1, y1, x2, y2)); } /** * Adds an allowed but not required line segment. * @param x1 X coordinate of end 1 * @param y1 Y coordinate of end 1 * @param x2 X coordinate of end 2 * @param y2 Y coordinate of end 2 */ public void allow(double x1, double y1, double x2, double y2) { allowed.add(new Line2D.Double(x1, y1, x2, y2)); } /** * Verifies that the argument matches the requirements. * In other words, all required lines must be present, and no extra lines may be present. * @param lines lines to check * @throws AssertionFailedError if the lines do not match the requirements */ public void check(List<Line2D> lines) { lines=new ArrayList<Line2D>(lines); List<Line2D> required=new ArrayList<Line2D>(this.required); for(Iterator<Line2D> reqItr = required.iterator(); reqItr.hasNext();) { Line2D requiredLine=reqItr.next(); for(Iterator<Line2D> itr = lines.iterator(); itr.hasNext();) { Line2D line = itr.next(); if(linesMatch(requiredLine, line)) { itr.remove(); reqItr.remove(); break; } } } for(Line2D allowedLine : allowed) { for(Iterator<Line2D> itr = lines.iterator(); itr.hasNext();) { Line2D line = itr.next(); if(linesMatch(allowedLine, line)) { itr.remove(); break; } } } if(!required.isEmpty() || !lines.isEmpty()) { StringBuffer msg = new StringBuffer(); msg.append("Missing lines:\n"); formatLines(msg, required); msg.append("Extra lines:\n"); formatLines(msg, lines); Assert.fail(msg.toString()); } } private void formatLines(StringBuffer msg, List<Line2D> lines) { for(Line2D line : lines) { msg.append("("); msg.append(line.getX1()); msg.append(", "); msg.append(line.getY1()); msg.append(") - ("); msg.append(line.getX2()); msg.append(", "); msg.append(line.getY2()); msg.append(")\n"); } } private boolean pointsMatch(double x1, double y1, double x2, double y2) { return Math.abs(x1 - x2) < error && Math.abs(y1 - y2) < error; } private boolean linesMatch(Line2D requiredLine, Line2D line) { double x1 = requiredLine.getX1(); double y1 = requiredLine.getY1(); double x2 = requiredLine.getX2(); double y2 = requiredLine.getY2(); double lineX1 = line.getX1(); double lineY1 = line.getY1(); double lineX2 = line.getX2(); double lineY2 = line.getY2(); // Check forward and backward if(pointsMatch(lineX1, lineY1, x1, y1) && pointsMatch(lineX2, lineY2, x2, y2)) { return true; } if(pointsMatch(lineX1, lineY1, x2, y2) && pointsMatch(lineX2, lineY2, x1, y1)) { return true; } return false; } }
false
Plotter_src_test_java_plotter_LineChecker.java
1,935
public class LinearTickMarkCalculator implements TickMarkCalculator { @Override public double[][] calculateTickMarks(Axis axis) { double start = axis.getStart(); double end = axis.getEnd(); double min = start; double max = end; if(min > max) { double tmp = max; max = min; min = tmp; } double diff = max - min; // d should be diff scaled to between 1 and 10 double d = diff / Math.pow(10, Math.floor(Math.log10(diff))); double adj = .1; while(d < 2) { d *= 2; adj *= 2; } while(d > 5) { d /= 2; adj *= 5; } double spacing = diff / d; double spacing2 = spacing * adj; double[] minorVals; double[] majorVals; if(min >= 0) { // In this case, both ends of the axis are non-negative. Go from min to max. double startCount = Math.ceil(min / spacing); double endCount = Math.floor(max / spacing); majorVals = new double[(int)(endCount - startCount) + 1]; double value = startCount * spacing; for(int i = 0; i < majorVals.length; i++) { majorVals[i] = value; value += spacing; } startCount = Math.ceil(min / spacing2); endCount = Math.floor(max / spacing2); minorVals = new double[(int) (endCount - startCount) + 1]; value = startCount * spacing2; for(int i = 0; i < minorVals.length; i++) { minorVals[i] = value; value += spacing2; } } else if(max <= 0) { // In this case, both ends of the axis are non-positive. Go from max to min. double startCount = Math.floor(max / spacing); double endCount = Math.ceil(min / spacing); majorVals = new double[(int) (startCount - endCount) + 1]; double value = startCount * spacing; for(int i = 0; i < majorVals.length; i++) { majorVals[i] = value; value -= spacing; } startCount = Math.floor(max / spacing2); endCount = Math.ceil(min / spacing2); minorVals = new double[(int) (startCount - endCount) + 1]; value = startCount * spacing2; for(int i = 0; i < minorVals.length; i++) { minorVals[i] = value; value -= spacing2; } } else { // In this case, one end is positive and one is negative. // Start from 0 and go in both directions to minimize rounding error. // Calculate the number of major ticks. There should be a better way. int majorCount = 0; double value = 0; while(value <= max) { value += spacing; majorCount++; } value = -spacing; while(value >= min) { value -= spacing; majorCount++; } majorVals = new double[majorCount]; value = 0; int i = 0; while(value <= max) { majorVals[i] = value; i++; value += spacing; } value = -spacing; while(value >= min) { majorVals[i] = value; i++; value -= spacing; } // Calculate the number of minor ticks. There should be a better way. int minorCount = 0; value = 0; while(value <= max) { value += spacing2; minorCount++; } value = -spacing2; while(value >= min) { value -= spacing2; minorCount++; } minorVals = new double[minorCount]; value = 0; i = 0; while(value <= max) { minorVals[i] = value; i++; value += spacing2; } value = -spacing2; while(value >= min) { minorVals[i] = value; i++; value -= spacing2; } } Arrays.sort(majorVals); return new double[][] {majorVals, minorVals}; } }
false
Plotter_src_main_java_plotter_LinearTickMarkCalculator.java
1,936
public class LogTickMarkCalculator implements TickMarkCalculator { // TODO: Make the ticks work at different scales @Override public double[][] calculateTickMarks(Axis axis) { double start = axis.getStart(); double end = axis.getEnd(); double min = start; double max = end; if(min > max) { double tmp = max; max = min; min = tmp; } double diff = max - min; // d should be diff scaled to between 1 and 10 double d = diff / Math.pow(10, Math.floor(Math.log10(diff))); double spacing = diff / d; double[] minorVals; double[] majorVals; double startCount = Math.ceil(min / spacing); double endCount = Math.floor(max / spacing); majorVals = new double[(int)(endCount - startCount) + 1]; double value = Math.ceil(min / spacing) * spacing; for(int i = 0; i < majorVals.length; i++) { majorVals[i] = value; value += spacing; } // TODO: Make the calculation for minor ticks efficient double base = Math.floor(min / spacing) * spacing; List<Double> mins = new ArrayList<Double>(); while(base <= max) { for(int i = 1; i < 10; i++) { value = base + Math.log10(i); if(value >= min && value <= max) { mins.add(value); } } base++; } minorVals = new double[mins.size()]; for(int i = 0; i < minorVals.length; i++) { minorVals[i] = mins.get(i); } return new double[][] {majorVals, minorVals}; } }
false
Plotter_src_main_java_plotter_LogTickMarkCalculator.java
1,937
public class MultiLineLabelUI extends BasicLabelUI { public static final String ROTATION_KEY = Rotation.class.getName(); public static final MultiLineLabelUI labelUI = new MultiLineLabelUI(); protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR) { String s = layoutCompoundLabel((JComponent) label, fontMetrics, splitStringByLines(text), icon, label .getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(), label .getHorizontalTextPosition(), viewR, iconR, textR, label.getIconTextGap()); if(s.equals("")) return text; return s; } /** * Compute and return the location of the icons origin, the * location of origin of the text baseline, and a possibly clipped * version of the compound labels string. Locations are computed * relative to the viewR rectangle. * The JComponents orientation (LEADING/TRAILING) will also be taken * into account and translated into LEFT/RIGHT values accordingly. */ public static String layoutCompoundLabel(JComponent c, FontMetrics fm, String[] text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) { boolean orientationIsLeftToRight = true; int hAlign = horizontalAlignment; int hTextPos = horizontalTextPosition; if(c != null) { if(!(c.getComponentOrientation().isLeftToRight())) { orientationIsLeftToRight = false; } } // Translate LEADING/TRAILING values in horizontalAlignment // to LEFT/RIGHT values depending on the components orientation switch(horizontalAlignment) { case LEADING: hAlign = (orientationIsLeftToRight) ? LEFT : RIGHT; break; case TRAILING: hAlign = (orientationIsLeftToRight) ? RIGHT : LEFT; break; } // Translate LEADING/TRAILING values in horizontalTextPosition // to LEFT/RIGHT values depending on the components orientation switch(horizontalTextPosition) { case LEADING: hTextPos = (orientationIsLeftToRight) ? LEFT : RIGHT; break; case TRAILING: hTextPos = (orientationIsLeftToRight) ? RIGHT : LEFT; break; } return layoutCompoundLabel(fm, text, icon, verticalAlignment, hAlign, verticalTextPosition, hTextPos, viewR, iconR, textR, textIconGap); } /** * Compute and return the location of the icons origin, the * location of origin of the text baseline, and a possibly clipped * version of the compound labels string. Locations are computed * relative to the viewR rectangle. * This layoutCompoundLabel() does not know how to handle LEADING/TRAILING * values in horizontalTextPosition (they will default to RIGHT) and in * horizontalAlignment (they will default to CENTER). * Use the other version of layoutCompoundLabel() instead. */ public static String layoutCompoundLabel(FontMetrics fm, String[] text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap) { /* Initialize the icon bounds rectangle iconR. */ if(icon != null) { iconR.width = icon.getIconWidth(); iconR.height = icon.getIconHeight(); } else { iconR.width = iconR.height = 0; } /* Initialize the text bounds rectangle textR. If a null * or and empty String was specified we substitute "" here * and use 0,0,0,0 for textR. */ // Fix for textIsEmpty sent by Paulo Santos boolean textIsEmpty = (text == null) || (text.length == 0) || (text.length == 1 && ((text[0] == null) || text[0].equals(""))); String rettext = ""; if(textIsEmpty) { textR.width = textR.height = 0; } else { Dimension dim = computeMultiLineDimension(fm, text); textR.width = dim.width; textR.height = dim.height; } /* Unless both text and icon are non-null, we effectively ignore * the value of textIconGap. The code that follows uses the * value of gap instead of textIconGap. */ int gap = (textIsEmpty || (icon == null)) ? 0 : textIconGap; if(!textIsEmpty) { /* If the label text string is too wide to fit within the available * space "..." and as many characters as will fit will be * displayed instead. */ int availTextWidth; if(horizontalTextPosition == CENTER) { availTextWidth = viewR.width; } else { availTextWidth = viewR.width - (iconR.width + gap); } if(textR.width > availTextWidth && text.length == 1) { String clipString = "..."; int totalWidth = SwingUtilities.computeStringWidth(fm, clipString); int nChars; for(nChars = 0; nChars < text[0].length(); nChars++) { totalWidth += fm.charWidth(text[0].charAt(nChars)); if(totalWidth > availTextWidth) { break; } } rettext = text[0].substring(0, nChars) + clipString; textR.width = SwingUtilities.computeStringWidth(fm, rettext); } } /* Compute textR.x,y given the verticalTextPosition and * horizontalTextPosition properties */ if(verticalTextPosition == TOP) { if(horizontalTextPosition != CENTER) { textR.y = 0; } else { textR.y = -(textR.height + gap); } } else if(verticalTextPosition == CENTER) { textR.y = (iconR.height / 2) - (textR.height / 2); } else { // (verticalTextPosition == BOTTOM) if(horizontalTextPosition != CENTER) { textR.y = iconR.height - textR.height; } else { textR.y = (iconR.height + gap); } } if(horizontalTextPosition == LEFT) { textR.x = -(textR.width + gap); } else if(horizontalTextPosition == CENTER) { textR.x = (iconR.width / 2) - (textR.width / 2); } else { // (horizontalTextPosition == RIGHT) textR.x = (iconR.width + gap); } /* labelR is the rectangle that contains iconR and textR. * Move it to its proper position given the labelAlignment * properties. * * To avoid actually allocating a Rectangle, Rectangle.union * has been inlined below. */ int labelR_x = Math.min(iconR.x, textR.x); int labelR_width = Math.max(iconR.x + iconR.width, textR.x + textR.width) - labelR_x; int labelR_y = Math.min(iconR.y, textR.y); int labelR_height = Math.max(iconR.y + iconR.height, textR.y + textR.height) - labelR_y; int dx, dy; if(verticalAlignment == TOP) { dy = viewR.y - labelR_y; } else if(verticalAlignment == CENTER) { dy = (viewR.y + (viewR.height / 2)) - (labelR_y + (labelR_height / 2)); } else { // (verticalAlignment == BOTTOM) dy = (viewR.y + viewR.height) - (labelR_y + labelR_height); } if(horizontalAlignment == LEFT) { dx = viewR.x - labelR_x; } else if(horizontalAlignment == RIGHT) { dx = (viewR.x + viewR.width) - (labelR_x + labelR_width); } else { // (horizontalAlignment == CENTER) dx = (viewR.x + (viewR.width / 2)) - (labelR_x + (labelR_width / 2)); } /* Translate textR and glypyR by dx,dy. */ textR.x += dx; textR.y += dy; iconR.x += dx; iconR.y += dy; return rettext; } protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY) { int accChar = l.getDisplayedMnemonic(); g.setColor(l.getForeground()); drawString(g, s, accChar, textX, textY); } protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY) { int accChar = l.getDisplayedMnemonic(); g.setColor(l.getBackground()); drawString(g, s, accChar, textX, textY); } protected void drawString(Graphics g, String s, int accChar, int textX, int textY) { if(s.indexOf('\n') == -1) BasicGraphicsUtils.drawString(g, s, accChar, textX, textY); else { String[] strs = splitStringByLines(s); int height = g.getFontMetrics().getHeight(); // Only the first line can have the accel char BasicGraphicsUtils.drawString(g, strs[0], accChar, textX, textY); for(int i = 1; i < strs.length; i++) g.drawString(strs[i], textX, textY + (height * i)); } } public static Dimension computeMultiLineDimension(FontMetrics fm, String[] strs) { int i, c, width = 0; for(i = 0, c = strs.length; i < c; i++) width = Math.max(width, SwingUtilities.computeStringWidth(fm, strs[i])); return new Dimension(width, fm.getHeight() * strs.length); } protected String str; protected String[] strs; public String[] splitStringByLines(String str) { if(str.equals(this.str)) return strs; this.str = str; int lines = 1; int i, c; for(i = 0, c = str.length(); i < c; i++) { if(str.charAt(i) == '\n') lines++; } strs = new String[lines]; StringTokenizer st = new StringTokenizer(str, "\n"); int line = 0; while(st.hasMoreTokens()) strs[line++] = st.nextToken(); return strs; } @Override public int getBaseline(JComponent c, int width, int height) { Rotation rotation = (Rotation) c.getClientProperty(ROTATION_KEY); if(rotation == Rotation.CCW || rotation == Rotation.CW) { return -1; } else if(rotation == Rotation.HALF) { int baseline = super.getBaseline(c, width, height); if(baseline < 0) { return baseline; } else { return height - baseline; } } return super.getBaseline(c, width, height); } @Override public BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { Rotation rotation = (Rotation) c.getClientProperty(ROTATION_KEY); if(rotation == Rotation.CCW || rotation == Rotation.CW) { return BaselineResizeBehavior.OTHER; } else if(rotation == Rotation.HALF) { BaselineResizeBehavior b = super.getBaselineResizeBehavior(c); if(b == BaselineResizeBehavior.CONSTANT_ASCENT) { return BaselineResizeBehavior.CONSTANT_DESCENT; } else if(b == BaselineResizeBehavior.CONSTANT_DESCENT) { return BaselineResizeBehavior.CONSTANT_ASCENT; } else { return b; } } return super.getBaselineResizeBehavior(c); } private static Rectangle paintIconR = new Rectangle(); private static Rectangle paintTextR = new Rectangle(); private static Rectangle paintViewR = new Rectangle(); private static Insets paintViewInsets = new Insets(0, 0, 0, 0); @Override public void paint(Graphics g, JComponent c) { // This method adapted from http://tech.chitgoks.com/2009/11/13/rotate-jlabel-vertically/ JLabel label = (JLabel) c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if((icon == null) && (text == null)) { return; } Rotation rotation = getRotation(c); FontMetrics fm = g.getFontMetrics(); paintViewInsets = c.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; if(rotation.isXYSwitched()) { paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); } else { paintViewR.width = c.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.height = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); } paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR); Graphics2D g2 = (Graphics2D) g; AffineTransform tr = g2.getTransform(); switch(rotation) { case NONE: break; case CW: g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); break; case CCW: g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); break; case HALF: g2.rotate(Math.PI); g2.translate(-c.getWidth(), -c.getHeight()); break; } if(icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if(text != null) { int textX = paintTextR.x; int textY = paintTextR.y + fm.getAscent(); if(label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); } } g2.setTransform(tr); } private Rotation getRotation(JComponent c) { Rotation rotation = (Rotation) c.getClientProperty(ROTATION_KEY); if(rotation == null) { rotation = Rotation.NONE; } return rotation; } @Override public Dimension getPreferredSize(JComponent c) { Dimension d = super.getPreferredSize(c); if(getRotation(c).isXYSwitched()) { d.setSize(d.getHeight(), d.getWidth()); } return d; } }
false
Plotter_src_main_java_plotter_MultiLineLabelUI.java
1,938
public abstract class Plot extends JComponent { private static final long serialVersionUID = 1L; /** * Converts a point from physical to logical coordinates. * The source and destination points may be the same object. * @param dest modified to contain the converted point * @param src point to convert */ public abstract void toLogical(Point2D dest, Point2D src); /** * Converts a point from logical to physical coordinates. * The source and destination points may be the same object. * @param dest modified to contain the converted point * @param src point to convert */ public abstract void toPhysical(Point2D dest, Point2D src); }
false
Plotter_src_main_java_plotter_Plot.java
1,939
public class PropertyTester { private final Object bean; private final BeanInfo beanInfo; public PropertyTester(Object bean) throws IntrospectionException { this.bean = bean; beanInfo = Introspector.getBeanInfo(bean.getClass()); } public void test(String propertyName, Object... values) throws InvocationTargetException, IllegalAccessException { PropertyDescriptor pd = null; for(PropertyDescriptor p : beanInfo.getPropertyDescriptors()) { if(p.getName().equals(propertyName)) { pd = p; break; } } Assert.assertNotNull("Property not found: " + propertyName, pd); Method readMethod = pd.getReadMethod(); Method writeMethod = pd.getWriteMethod(); Assert.assertNotNull("Getter not found: " + propertyName, readMethod); Assert.assertNotNull("Setter not found: " + propertyName, writeMethod); if(values == null || values.length == 0) { Class<?> type = pd.getPropertyType(); if(type == boolean.class) { values = new Object[] { true, false }; } else if(type == Boolean.class) { values = new Object[] { true, false, null }; } else if(type == byte.class) { values = new Object[] { (byte) 0, Byte.MAX_VALUE, Byte.MIN_VALUE, (byte) 1, (byte) -1 }; } else if(type == Byte.class) { values = new Object[] { (byte) 0, Byte.MAX_VALUE, Byte.MIN_VALUE, (byte) 1, (byte) -1, null }; } else if(type == short.class) { values = new Object[] { (short) 0, Short.MAX_VALUE, Short.MIN_VALUE, (short) 1, (short) -1 }; } else if(type == Short.class) { values = new Object[] { (short) 0, Short.MAX_VALUE, Short.MIN_VALUE, (short) 1, (short) -1, null }; } else if(type == char.class) { values = new Object[] { (char) 0, Character.MAX_VALUE, 'a', '1', '.', '\\', ' ', '\n' }; } else if(type == Character.class) { values = new Object[] { (char) 0, Character.MAX_VALUE, 'a', '1', '.', '\\', ' ', '\n', null }; } else if(type == int.class) { values = new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, 1, -1 }; } else if(type == Integer.class) { values = new Object[] { 0, Integer.MAX_VALUE, Integer.MIN_VALUE, 1, -1, null }; } else if(type == long.class) { values = new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, 1L, -1L }; } else if(type == Long.class) { values = new Object[] { 0L, Long.MAX_VALUE, Long.MIN_VALUE, 1L, -1L, null }; } else if(type == float.class) { values = new Object[] { 0.0f, 1.0f, -1.0f, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN, Float.MAX_VALUE, Float.MIN_VALUE }; } else if(type == Float.class) { values = new Object[] { 0.0f, 1.0f, -1.0f, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NaN, Float.MAX_VALUE, Float.MIN_VALUE, null }; } else if(type == double.class) { values = new Object[] { 0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, Double.MAX_VALUE, Double.MIN_VALUE }; } else if(type == Double.class) { values = new Object[] { 0.0, 1.0, -1.0, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NaN, Double.MAX_VALUE, Double.MIN_VALUE, null }; } else if(type == String.class) { values = new Object[] { null, "", " ", "test", "This is a test." }; } else { Assert.fail("Values must be provided to test a property of type " + type.getName()); } } for(Object value : values) { writeMethod.invoke(bean, value); Object value2 = readMethod.invoke(bean); Assert.assertEquals(value, value2); } } }
false
Plotter_src_test_java_plotter_PropertyTester.java
1,940
public enum Rotation { /** No rotation. */ NONE(false), /** Clockwise 90 degrees. */ CW(true), /** Counter clockwise 90 degrees. */ CCW(true), /** 180 degrees, or a half rotation. */ HALF(false); /** True if X and Y are switched. */ private final boolean xySwitched; private Rotation(boolean xySwitched) { this.xySwitched = xySwitched; } /** * Returns true if X and Y are switched. * @return true if X and Y are switched */ public boolean isXYSwitched() { return xySwitched; } }
false
Plotter_src_main_java_plotter_Rotation.java
1,941
public class Shapes { /** * Creates a square with side length <code>2 * scale</code>. * @param scale scale of the shape * @return square with side length <code>2 * scale</code> */ public static Shape square(double scale) { GeneralPath shape = new GeneralPath(); shape.moveTo(-scale, -scale); shape.lineTo(-scale, scale); shape.lineTo(scale, scale); shape.lineTo(scale, -scale); shape.lineTo(-scale, -scale); return shape; } /** * Creates a circle with radius <code>scale</code>. * @param scale scale of the shape * @return circle with radius <code>scale</code> */ public static Shape circle(double scale) { return new Ellipse2D.Double(-scale, -scale, scale * 2, scale * 2); } /** * Creates an upward-pointing triangle. * @param scale scale of the shape * @return upward-pointing triangle */ public static Shape triangleUp(double scale) { GeneralPath shape = new GeneralPath(); shape.moveTo(0, -scale); double alpha = -Math.PI / 6; double y = -scale * Math.sin(alpha); double x = scale * Math.cos(alpha); shape.lineTo(x, y); shape.lineTo(-x, y); shape.lineTo(0, -scale); return shape; } /** * Creates an downward-pointing triangle. * @param scale scale of the shape * @return downward-pointing triangle */ public static Shape triangleDown(double scale) { GeneralPath shape = new GeneralPath(); shape.moveTo(0, scale); double alpha = -Math.PI / 6; double y = scale * Math.sin(alpha); double x = scale * Math.cos(alpha); shape.lineTo(x, y); shape.lineTo(-x, y); shape.lineTo(0, scale); return shape; } /** * Creates a space shuttle. * @param scale scale of the shape * @return space shuttle */ public static Shape shuttle(double scale) { double engineX = .15; double engineY = .82; double engineY2 = .2; double wingX = .69; double wingY = engineY - .1; double wing2X = .91 * wingX; double wing2Y = wingY - .24; double wing3X = .45 * wing2X; double wing3Y = .15; double fuselageX = .15; double cockpitY = -.6; GeneralPath shape = new GeneralPath(); // engine shape.moveTo(-engineX, 1); shape.lineTo(engineX, 1); shape.lineTo(engineY2, engineY); // right wing shape.lineTo(wingX, wingY); shape.lineTo(wing2X, wing2Y); shape.lineTo(wing3X, wing3Y); shape.lineTo(fuselageX, cockpitY); // cockpit shape.curveTo(fuselageX, cockpitY - .2, .05, -1, 0, -1); shape.curveTo(-.05, -1, -fuselageX, cockpitY - .2, -fuselageX, cockpitY); // left wing shape.lineTo(-wing3X, wing3Y); shape.lineTo(-wing2X, wing2Y); shape.lineTo(-wingX, wingY); // engine shape.lineTo(-engineY2, engineY); shape.lineTo(-engineX, 1); shape.transform(AffineTransform.getScaleInstance(scale, scale)); return shape; } /** * Creates an asterisk. * @param scale scale of the shape * @return asterisk */ public static Shape star(double scale) { GeneralPath shape = new GeneralPath(); for(int i = 0; i < 6; i++) { shape.moveTo(0, 0); shape.lineTo(scale * Math.cos(i * Math.PI / 3), scale * Math.sin(i * Math.PI / 3)); } return shape; } /** * Creates a plus or cross. * @param scale scale of the shape * @return plus */ public static Shape plus(double scale) { GeneralPath shape = new GeneralPath(); for(int i = 0; i < 4; i++) { shape.moveTo(0, 0); shape.lineTo(scale * Math.cos(i * Math.PI / 2), scale * Math.sin(i * Math.PI / 2)); } return shape; } /** * Creates an 'x'. * @param scale scale of the shape * @return 'x' shape */ public static Shape x(double scale) { GeneralPath shape = new GeneralPath(); for(int i = 0; i < 4; i++) { shape.moveTo(0, 0); double alpha = i * Math.PI / 2 + Math.PI / 4; shape.lineTo(scale * Math.cos(alpha), scale * Math.sin(alpha)); } return shape; } }
false
Plotter_src_main_java_plotter_Shapes.java
1,942
public interface TickMarkCalculator { /** * Calculates tick marks. * The values of major and minor tick marks are returned. * Major values <b>must</b> be in sorted order. * @param axis axis that needs tick marks and labels * @return values of the major tick marks at index 0, and the minor tick marks at index 1 */ public double[][] calculateTickMarks(Axis axis); }
false
Plotter_src_main_java_plotter_TickMarkCalculator.java
1,943
public class TimeTickMarkCalculator implements TickMarkCalculator { private static final long MINUTE = 60 * 1000; private static final long HOUR = 60 * MINUTE; private static final long DAY = 24 * HOUR; @Override public double[][] calculateTickMarks(Axis axis) { double start = axis.getStart(); double end = axis.getEnd(); double min = start; double max = end; if(min > max) { double tmp = max; max = min; min = tmp; } double diff = max - min; double spacing; double spacing2; // TODO: Clean this up if(diff > 2 * DAY) { double days = diff / DAY; // d should be days scaled to between 1 and 10 double d = days / Math.pow(10, Math.floor(Math.log10(days))); double adj; if(d < 2) { d *= 2; adj = .2; } else if(d > 5) { d *= .5; adj = .5; } else { adj = .5; } spacing = DAY * days / d; spacing2 = spacing * adj; } else if(diff > 2 * HOUR) { double hours = diff / HOUR; if(hours > 24) { spacing = 12 * HOUR; spacing2 = 6 * HOUR; } else if(hours > 12) { spacing = 6 * HOUR; spacing2 = 2 * HOUR; } else { spacing = 2 * HOUR; spacing2 = HOUR; } } else if(diff > 2 * MINUTE) { double minutes = diff / MINUTE; if(minutes > 60) { spacing = 30 * MINUTE; spacing2 = 10 * MINUTE; } else if(minutes > 30) { spacing = 15 * MINUTE; spacing2 = 5 * MINUTE; } else if(minutes > 20) { spacing = 10 * MINUTE; spacing2 = 5 * MINUTE; } else if(minutes > 10) { spacing = 5 * MINUTE; spacing2 = MINUTE; } else { spacing = 2 * MINUTE; spacing2 = MINUTE; } } else if(diff > 2 * 1000) { double seconds = diff / 1000; if(seconds > 60) { spacing = 30 * 1000; spacing2 = 10 * 1000; } else if(seconds > 30) { spacing = 15 * 1000; spacing2 = 5 * 1000; } else if(seconds > 20) { spacing = 10 * 1000; spacing2 = 5 * 1000; } else if(seconds > 10) { spacing = 5 * 1000; spacing2 = 1000; } else { spacing = 2000; spacing2 = 1000; } } else { // d should be diff scaled to between 1 and 10 double d = diff / Math.pow(10, Math.floor(Math.log10(diff))); double adj; if(d < 2) { d *= 2; adj = .2; } else if(d > 5) { d /= 2; adj = .5; } else { adj = .5; } spacing = diff / d; spacing2 = spacing * adj; } double[] majorVals; double[] minorVals; if(min >= 0) { // In this case, both ends of the axis are non-negative. Go from min to max. double startCount = Math.ceil(min / spacing); double endCount = Math.floor(max / spacing); majorVals = new double[(int)(endCount - startCount) + 1]; double value = startCount * spacing; for(int i = 0; i < majorVals.length; i++) { majorVals[i] = value; value += spacing; } startCount = Math.ceil(min / spacing2); endCount = Math.floor(max / spacing2); minorVals = new double[(int) (endCount - startCount) + 1]; value = startCount * spacing2; for(int i = 0; i < minorVals.length; i++) { minorVals[i] = value; value += spacing2; } } else if(max <= 0) { // In this case, both ends of the axis are non-positive. Go from max to min. double startCount = Math.floor(max / spacing); double endCount = Math.ceil(min / spacing); majorVals = new double[(int) (startCount - endCount) + 1]; double value = startCount * spacing; for(int i = 0; i < majorVals.length; i++) { majorVals[i] = value; value -= spacing; } startCount = Math.floor(max / spacing2); endCount = Math.ceil(min / spacing2); minorVals = new double[(int) (startCount - endCount) + 1]; value = startCount * spacing2; for(int i = 0; i < minorVals.length; i++) { minorVals[i] = value; value -= spacing2; } } else { // In this case, one end is positive and one is negative. // Start from 0 and go in both directions to minimize rounding error. // Calculate the number of major ticks. There should be a better way. int majorCount = 0; double value = 0; while(value <= max) { value += spacing; majorCount++; } value = -spacing; while(value >= min) { value -= spacing; majorCount++; } majorVals = new double[majorCount]; value = 0; int i = 0; while(value <= max) { majorVals[i] = value; i++; value += spacing; } value = -spacing; while(value >= min) { majorVals[i] = value; i++; value -= spacing; } // Calculate the number of minor ticks. There should be a better way. int minorCount = 0; value = 0; while(value <= max) { value += spacing2; minorCount++; } value = -spacing2; while(value >= min) { value -= spacing2; minorCount++; } minorVals = new double[minorCount]; value = 0; i = 0; while(value <= max) { minorVals[i] = value; i++; value += spacing2; } value = -spacing2; while(value >= min) { minorVals[i] = value; i++; value -= spacing2; } } Arrays.sort(majorVals); return new double[][] {majorVals, minorVals}; } }
false
Plotter_src_main_java_plotter_TimeTickMarkCalculator.java
1,944
public class BigLabels { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); ((LinearXYAxis)xAxis).setFormat(new DecimalFormat("0.0000000")); ((LinearXYAxis)yAxis).setFormat(new DecimalFormat("0.0000000")); ((LinearXYAxis)yAxis).setLabelRotation(Rotation.CCW); for(int x = 0; x <= 100; x++) { double x2 = x / 100.0 * 2 * Math.PI; double y2 = Math.sin(x2); d.add(x2, y2); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_BigLabels.java
1,945
public class Compression { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); JPanel uncompressedContents = new JPanel(); contentPane.add(uncompressedContents); final JPanel compressedContents = new JPanel(); contentPane.add(compressedContents); contentPane.setLayout(new GridLayout(2, 1)); final SimpleXYDataset d = createPlot(uncompressedContents); final SimpleXYDataset d2 = createPlot(compressedContents); double value = 0; double signal = 0; Random random = new Random(); for(int i = 0; i < 5000; i++) { value = value * .99 + random.nextGaussian(); signal = signal * .99 + random.nextGaussian(); double y = value; if(signal < -1) { y = Double.NaN; } d.add(i, y); } for(int i = 0; i < 1000; i++) { value = (i / 100) % 2 - .5; d.add(i + 5000, value * 30); } for(int i = 0; i < 1000; i++) { value = i % 2 - .5; d.add(i + 6000, value * 30); } for(int i = 0; i < 1000; i++) { int j = i % 6; if(j == 0) { value = -.5; } else if(j == 1) { value = -.25; } else if(j == 2) { value = Double.NaN; } else if(j == 3) { value = .25; } else if(j == 4) { value = .5; } else if(j == 5) { value = Double.NaN; } d.add(i + 7000, value * 30); } for(int i = 0; i < 1000; i++) { int j = i % 100; if(j == 0) { value = Double.NaN; } else if(j < 50) { value = -.5; } else if(j == 50) { value = Double.NaN; } else { value = .5; } d.add(i + 8000, value * 30); } for(int i = 0; i < 1000; i++) { double x = (1000 - i) / 10000.0; value = Math.sin(x + 1 / x); d.add(i + 9000, value * 15); } compressedContents.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { compress(compressedContents, d, d2); } }); compress(compressedContents, d, d2); frame.setSize(400, 300); frame.setVisible(true); } private static void compress(JPanel compressedContents, final SimpleXYDataset d, final SimpleXYDataset d2) { double scale = 10000.0 / compressedContents.getWidth(); DefaultCompressor compressor = new DefaultCompressor(); PointData input = new PointData(d.getXData(), d.getYData()); PointData output = new PointData(); compressor.compress(input, output, 0, scale); int size = d.getPointCount(); int size2 = output.getX().getLength(); DoubleData x = output.getX(); DoubleData y = output.getY(); d2.removeAllPoints(); for(int i = 0; i < size2; i++) { d2.add(x.get(i), y.get(i)); } System.out.println("Input size: " + size); System.out.println("Output size: " + size2); System.out.println("Points per pixel: " + size2 / (double) compressedContents.getWidth()); System.out.println("Compression ratio: " + 100.0 * (size - size2) / (double) size); } private static SimpleXYDataset createPlot(Container contentPane) { final XYPlot plot = new XYPlot(); XYAxis xAxis = new LinearXYAxis(XYDimension.X); XYAxis yAxis = new LinearXYAxis(XYDimension.Y); xAxis.setPreferredSize(new Dimension(1, 40)); yAxis.setPreferredSize(new Dimension(40, 1)); xAxis.setForeground(Color.white); yAxis.setForeground(Color.white); xAxis.setTextMargin(10); yAxis.setTextMargin(10); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); plot.setBackground(Color.darkGray); XYPlotContents contents = new XYPlotContents(); contents.setBackground(Color.black); plot.setBackground(Color.darkGray); XYGrid grid = new XYGrid(xAxis, yAxis); grid.setForeground(Color.lightGray); contents.add(grid); plot.add(contents); plot.setPreferredSize(new Dimension(150, 100)); contentPane.setBackground(Color.darkGray); XYLocationDisplay locationDisplay = new XYLocationDisplay(); // This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty. // Note that mimimumSize does not work for some reason. locationDisplay.setText("Ag"); Dimension size = locationDisplay.getPreferredSize(); size.width = 100; locationDisplay.setText(""); locationDisplay.setPreferredSize(size); // End hack locationDisplay.setForeground(Color.white); locationDisplay.setFont(new Font("Arial", 0, 12)); locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1}</html>")); locationDisplay.attach(plot); plot.add(locationDisplay); SlopeLine slopeLine = new SlopeLine(); slopeLine.setForeground(Color.white); slopeLine.attach(plot); SlopeLineDisplay slopeLineDisplay = new SlopeLineDisplay(); slopeLine.addListenerForPlot(plot, slopeLineDisplay); slopeLineDisplay.setFont(new Font("Arial", 0, 12)); slopeLineDisplay.setForeground(Color.white); slopeLineDisplay.setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0} <b>&Delta;y:</b> {1}</html>")); plot.add(slopeLineDisplay); contentPane.add(plot); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); new DefaultXYLayoutGenerator().generateLayout(plot); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(10000); d.setXData(line.getXData()); d.setYData(line.getYData()); contents.add(line); contents.setComponentZOrder(grid, contents.getComponentCount() - 1); yAxis.setStart(-20); yAxis.setEnd(20); xAxis.setStart(0); xAxis.setEnd(10000); return d; } }
false
Plotter_src_examples_java_plotter_examples_Compression.java
1,946
compressedContents.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { compress(compressedContents, d, d2); } });
false
Plotter_src_examples_java_plotter_examples_Compression.java
1,947
public class Enumeration { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); yAxis.setPreferredSize(new Dimension(75, 50)); xAxis.setStartMargin(75); ((LinearXYAxis) yAxis).setFormat(new ChoiceFormat(new double[] {-Double.POSITIVE_INFINITY, 0, 1, 2, 2.000001}, new String[] {"", "red", "green", "blue", ""})); ((LinearXYAxis) yAxis).setTickMarkCalculator(new IntegerTickMarkCalculator()); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); line.setLineMode(LineMode.STEP_YX); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1); yAxis.setEnd(3); xAxis.setStart(0); xAxis.setEnd(10); d.add(2, 0); d.add(3, 1); d.add(4, 2); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_Enumeration.java
1,948
public class InvertedAxes { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(2, 2)); JPanel[] panels = new JPanel[4]; SimpleXYDataset[] datasets = new SimpleXYDataset[panels.length]; for(int i = 0; i < panels.length; i++) { panels[i] = new JPanel(); contentPane.add(panels[i]); datasets[i] = createPlot(panels[i], i % 2 == 1, i > 1); for(int j = 0; j < 100; j++) { datasets[i].add(j/20.0, Math.exp(j/20.0)); } } frame.setSize(400, 300); frame.setVisible(true); } private static SimpleXYDataset createPlot(Container contentPane, boolean invertX, boolean invertY) { final XYPlot plot = new XYPlot(); XYAxis xAxis = new LinearXYAxis(XYDimension.X); XYAxis yAxis = new LinearXYAxis(XYDimension.Y); xAxis.setPreferredSize(new Dimension(1, 40)); yAxis.setPreferredSize(new Dimension(40, 1)); xAxis.setForeground(Color.white); yAxis.setForeground(Color.white); xAxis.setTextMargin(10); yAxis.setTextMargin(10); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); plot.setBackground(Color.darkGray); XYPlotContents contents = new XYPlotContents(); contents.setBackground(Color.black); plot.setBackground(Color.darkGray); XYGrid grid = new XYGrid(xAxis, yAxis); grid.setForeground(Color.lightGray); contents.add(grid); plot.add(contents); plot.setPreferredSize(new Dimension(150, 100)); contentPane.setBackground(Color.darkGray); XYLocationDisplay locationDisplay = new XYLocationDisplay(); // This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty. // Note that mimimumSize does not work for some reason. locationDisplay.setText("Ag"); Dimension size = locationDisplay.getPreferredSize(); size.width = 100; locationDisplay.setText(""); locationDisplay.setPreferredSize(size); // End hack locationDisplay.setForeground(Color.white); locationDisplay.setFont(new Font("Arial", 0, 12)); locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1}</html>")); locationDisplay.attach(plot); plot.add(locationDisplay); SlopeLine slopeLine = new SlopeLine(); slopeLine.setForeground(Color.white); slopeLine.attach(plot); SlopeLineDisplay slopeLineDisplay = new SlopeLineDisplay(); slopeLine.addListenerForPlot(plot, slopeLineDisplay); slopeLineDisplay.setFont(new Font("Arial", 0, 12)); slopeLineDisplay.setForeground(Color.white); slopeLineDisplay.setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0} <b>&Delta;y:</b> {1}</html>")); plot.add(slopeLineDisplay); new DefaultXYLayoutGenerator().generateLayout(plot); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.X_AXIS)); contentPane.add(plot); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(10000); d.setXData(line.getXData()); d.setYData(line.getYData()); contents.add(line); contents.setComponentZOrder(grid, contents.getComponentCount() - 1); if(invertY) { yAxis.setStart(200); yAxis.setEnd(0); } else { yAxis.setStart(0); yAxis.setEnd(200); } if(invertX) { xAxis.setStart(5); xAxis.setEnd(0); } else { xAxis.setStart(0); xAxis.setEnd(5); } return d; } }
false
Plotter_src_examples_java_plotter_examples_InvertedAxes.java
1,949
public class LogPlot { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame() { private static final long serialVersionUID = 1L; @Override protected XYAxis createYAxis() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setTickMarkCalculator(new LogTickMarkCalculator()); axis.setFormat(new ExpFormat(new DecimalFormat("#.#"))); return axis; } }; frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(3.2); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); for(int x = 0; x <= 100; x++) { double x2 = x / 100.0 * 2 * Math.PI; double y2 = 100 * (Math.sin(x2) + 1) + 1; d.add(x2, Math.log10(y2)); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_LogPlot.java
1,950
XYPlotFrame frame = new XYPlotFrame() { private static final long serialVersionUID = 1L; @Override protected XYAxis createYAxis() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setTickMarkCalculator(new LogTickMarkCalculator()); axis.setFormat(new ExpFormat(new DecimalFormat("#.#"))); return axis; } };
false
Plotter_src_examples_java_plotter_examples_LogPlot.java
1,951
public class MissingPointModes { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); LinearXYPlotLine[] lines = new LinearXYPlotLine[8]; SimpleXYDataset[] datasets = new SimpleXYDataset[lines.length]; for(int i = 0; i < lines.length; i++) { LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); lines[i] = line; datasets[i] = d; } yAxis.setStart(0); yAxis.setEnd(11); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); lines[0].setMissingPointMode(MissingPointMode.NONE); lines[1].setMissingPointMode(MissingPointMode.LEFT); lines[2].setMissingPointMode(MissingPointMode.RIGHT); lines[3].setMissingPointMode(MissingPointMode.BOTH); lines[4].setMissingPointMode(MissingPointMode.NONE); lines[5].setMissingPointMode(MissingPointMode.LEFT); lines[6].setMissingPointMode(MissingPointMode.RIGHT); lines[7].setMissingPointMode(MissingPointMode.BOTH); lines[0].setForeground(Color.white); lines[1].setForeground(Color.blue); lines[2].setForeground(Color.cyan); lines[3].setForeground(Color.gray); lines[4].setForeground(Color.green); lines[5].setForeground(Color.magenta); lines[6].setForeground(Color.orange); lines[7].setForeground(Color.red); // Note that line[0] is at the top for(int i = 0; i < datasets.length; i++) { SimpleXYDataset d = datasets[i]; double offset = datasets.length - 1 - i; if(i >= datasets.length / 2) { d.add(0, Double.NaN); } d.add(1, 1.5 + offset); d.add(2, 1 + offset); d.add(3, Double.NaN); d.add(4, 1.25 + offset); d.add(5, 1.75 + offset); if(i >= datasets.length / 2) { d.add(6, Double.NaN); } } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_MissingPointModes.java
1,952
public class PointShapes { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); List<Shape> shapes = new ArrayList<Shape>(); shapes.add(Shapes.square(5)); shapes.add(Shapes.circle(5)); shapes.add(Shapes.triangleUp(5)); shapes.add(Shapes.triangleDown(5)); shapes.add(Shapes.shuttle(5)); shapes.add(Shapes.star(5)); shapes.add(Shapes.plus(5)); shapes.add(Shapes.x(5)); LinearXYPlotLine[] lines = new LinearXYPlotLine[shapes.size() * 2]; SimpleXYDataset[] datasets = new SimpleXYDataset[lines.length]; for(int i = 0; i < lines.length; i++) { LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); if(i % 2 == 0) { line.setPointOutline(shapes.get(i / 2)); } else { line.setPointFill(shapes.get(i / 2)); } lines[i] = line; datasets[i] = d; } yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); for(int x = 0; x <= 10; x++) { double x2 = x / 10.0 * 2 * Math.PI; for(int i = 0; i < datasets.length; i++) { datasets[i].add(x2, Math.sin(x2 - Math.PI * i / datasets.length)); } } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_PointShapes.java
1,953
public class RotatedLabels { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); ((LinearXYAxis)xAxis).setFormat(new DecimalFormat("0.0")); xAxis.setLabelRotation(Rotation.CCW); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); for(int x = 0; x <= 100; x++) { double x2 = x / 100.0 * 2 * Math.PI; double y2 = Math.sin(x2); d.add(x2, y2); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_RotatedLabels.java
1,954
public class ScatterPlot { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final ScatterXYPlotLine line = new ScatterXYPlotLine(xAxis, yAxis); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(-1.2); xAxis.setEnd(1.2); int n = 2000; for(int x = 0; x <= n; x++) { double theta = x / (double) n * 2 * Math.PI; double x2 = Math.cos(theta) + .2 * Math.cos(theta * 20); double y2 = Math.sin(theta) + .2 * Math.sin(theta * 20); d.add(x2, y2); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_ScatterPlot.java
1,955
public class ScatterPlotUpdating { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final long[] paintTime=new long[1]; final long[] paints=new long[1]; final ScatterXYPlotLine line = new ScatterXYPlotLine(xAxis, yAxis) { int skip; @Override protected void paintComponent(Graphics g) { long start = System.nanoTime(); super.paintComponent(g); if(skip++>1000) { paintTime[0] += System.nanoTime() - start; paints[0]++; } } }; line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(-1.2); xAxis.setEnd(1.2); final int n = 2000; for(int x = 0; x <= n; x++) { double theta = x / (double) n * 2 * Math.PI; double x2 = Math.cos(theta) + .2 * Math.cos(theta * 20); double y2 = Math.sin(theta) + .2 * Math.sin(theta * 20); d.add(x2, y2); } frame.setSize(400, 300); frame.setVisible(true); Timer timer = new Timer(); timer.schedule(new TimerTask() { int x = 2000; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { double theta = x / (double) n * 2 * Math.PI; double x2 = Math.cos(theta) + .2 * Math.cos(theta * 20); double y2 = Math.sin(theta) + .2 * Math.sin(theta * 20); d.add(x2, y2); if(x % 10 == 0 && paints[0] > 0) { System.out.println("Average paint time: " + paintTime[0] / paints[0]); } } }); } }, 100, 100); } }
false
Plotter_src_examples_java_plotter_examples_ScatterPlotUpdating.java
1,956
final ScatterXYPlotLine line = new ScatterXYPlotLine(xAxis, yAxis) { int skip; @Override protected void paintComponent(Graphics g) { long start = System.nanoTime(); super.paintComponent(g); if(skip++>1000) { paintTime[0] += System.nanoTime() - start; paints[0]++; } } };
false
Plotter_src_examples_java_plotter_examples_ScatterPlotUpdating.java
1,957
timer.schedule(new TimerTask() { int x = 2000; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { double theta = x / (double) n * 2 * Math.PI; double x2 = Math.cos(theta) + .2 * Math.cos(theta * 20); double y2 = Math.sin(theta) + .2 * Math.sin(theta * 20); d.add(x2, y2); if(x % 10 == 0 && paints[0] > 0) { System.out.println("Average paint time: " + paintTime[0] / paints[0]); } } }); } }, 100, 100);
false
Plotter_src_examples_java_plotter_examples_ScatterPlotUpdating.java
1,958
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { double theta = x / (double) n * 2 * Math.PI; double x2 = Math.cos(theta) + .2 * Math.cos(theta * 20); double y2 = Math.sin(theta) + .2 * Math.sin(theta * 20); d.add(x2, y2); if(x % 10 == 0 && paints[0] > 0) { System.out.println("Average paint time: " + paintTime[0] / paints[0]); } } });
false
Plotter_src_examples_java_plotter_examples_ScatterPlotUpdating.java
1,959
public class ScatterPointShapes { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final ScatterXYPlotLine line = new ScatterXYPlotLine(xAxis, yAxis); GeneralPath pointShape = new GeneralPath(); pointShape.moveTo(-5, -5); pointShape.lineTo(-5, 5); pointShape.lineTo(5, 5); pointShape.lineTo(5, -5); pointShape.lineTo(-5, -5); line.setPointFill(pointShape); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-10); yAxis.setEnd(10); xAxis.setStart(-10); xAxis.setEnd(10); for(int p = 0; p <= 10; p++) { double r = p; double theta = p; double x = r * Math.cos(theta); double y = r * Math.sin(theta); d.add(x, y); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_ScatterPointShapes.java
1,960
public class Scrolling { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); Timer timer = new Timer(); final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis(); final XYAxis yAxis = frame.getYAxis(); xAxis.setTickMarkCalculator(new TimeTickMarkCalculator()); xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS"))); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); final XYMarkerLine marker = new XYMarkerLine(xAxis, 60); marker.setForeground(Color.yellow); XYPlotContents contents = frame.getContents(); contents.add(marker); final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5); marker2.setForeground(Color.red); contents.add(marker2); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(10); frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>")); frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss} <b>&Delta;y:</b> {1}</html>")); for(int x = 0; x < 900; x++) { double x2 = x / 10.0; double y2 = Math.sin(x2 / 10.0); d.add(x2, y2); } timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } }); } }, 100, 100); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_Scrolling.java
1,961
timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } }); } }, 100, 100);
false
Plotter_src_examples_java_plotter_examples_Scrolling.java
1,962
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } });
false
Plotter_src_examples_java_plotter_examples_Scrolling.java
1,963
public class ScrollingCompression { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); Timer timer = new Timer(); final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis(); final XYAxis yAxis = frame.getYAxis(); xAxis.setTickMarkCalculator(new TimeTickMarkCalculator()); xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS"))); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final CompressingXYDataset d = new CompressingXYDataset(line, new DefaultCompressor()); d.setTruncationPoint(0); d.setXData(line.getXData()); d.setYData(line.getYData()); final XYMarkerLine marker = new XYMarkerLine(xAxis, 60); marker.setForeground(Color.yellow); XYPlotContents contents = frame.getContents(); contents.add(marker); final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5); marker2.setForeground(Color.red); contents.add(marker2); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(10); frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>")); frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss} <b>&Delta;y:</b> {1}</html>")); for(int x = 0; x < 900; x++) { double x2 = x / 10.0; double y2 = Math.sin(x2 / 10.0); d.add(x2, y2); } timer.schedule(new TimerTask() { int x = 0; long startTime = System.currentTimeMillis(); @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); d.setTruncationPoint(xAxis.getStart()); for(int i = 0; i < 10; i++) { double x2 = now + i; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); x++; if(x % 100 == 0) { System.out.println("Dataset size: " + d.getPointCount()); System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth()); System.out.println("Points per second: " + 1000 * x / (double) (now - startTime)); } } } }); } }, 10, 10); line.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { d.setCompressionOffset(xAxis.getStart()); d.setCompressionScale((xAxis.getEnd() - xAxis.getStart()) / xAxis.getWidth()); } }); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_ScrollingCompression.java
1,964
timer.schedule(new TimerTask() { int x = 0; long startTime = System.currentTimeMillis(); @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); d.setTruncationPoint(xAxis.getStart()); for(int i = 0; i < 10; i++) { double x2 = now + i; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); x++; if(x % 100 == 0) { System.out.println("Dataset size: " + d.getPointCount()); System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth()); System.out.println("Points per second: " + 1000 * x / (double) (now - startTime)); } } } }); } }, 10, 10);
false
Plotter_src_examples_java_plotter_examples_ScrollingCompression.java
1,965
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now / 1000 * 1000 - 9000); xAxis.setEnd(now / 1000 * 1000 + 1000); d.setTruncationPoint(xAxis.getStart()); for(int i = 0; i < 10; i++) { double x2 = now + i; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); x++; if(x % 100 == 0) { System.out.println("Dataset size: " + d.getPointCount()); System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth()); System.out.println("Points per second: " + 1000 * x / (double) (now - startTime)); } } } });
false
Plotter_src_examples_java_plotter_examples_ScrollingCompression.java
1,966
line.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { d.setCompressionOffset(xAxis.getStart()); d.setCompressionScale((xAxis.getEnd() - xAxis.getStart()) / xAxis.getWidth()); } });
false
Plotter_src_examples_java_plotter_examples_ScrollingCompression.java
1,967
public class ScrollingTimeOnY { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); Timer timer = new Timer(); final LinearXYAxis yAxis = (LinearXYAxis) frame.getYAxis(); final XYAxis xAxis = frame.getXAxis(); yAxis.setTickMarkCalculator(new TimeTickMarkCalculator()); yAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS"))); yAxis.setPreferredSize(new Dimension(100, 50)); xAxis.setStartMargin(100); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.Y); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); final XYMarkerLine marker = new XYMarkerLine(xAxis, 60); marker.setForeground(Color.yellow); XYPlotContents contents = frame.getContents(); contents.add(marker); final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5); marker2.setForeground(Color.red); contents.add(marker2); frame.addPlotLine(line); yAxis.setStart(0); yAxis.setEnd(10); xAxis.setStart(-1.2); xAxis.setEnd(1.2); frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1,date,HH:mm:ss}</html>")); frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0} <b>&Delta;y:</b> {1,date,HH:mm:ss}</html>")); timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); yAxis.setStart(now / 1000 * 1000 - 9000); yAxis.setEnd(now / 1000 * 1000 + 1000); double y2 = now; double x2 = Math.sin(y2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } }); } }, 100, 100); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_ScrollingTimeOnY.java
1,968
timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); yAxis.setStart(now / 1000 * 1000 - 9000); yAxis.setEnd(now / 1000 * 1000 + 1000); double y2 = now; double x2 = Math.sin(y2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } }); } }, 100, 100);
false
Plotter_src_examples_java_plotter_examples_ScrollingTimeOnY.java
1,969
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); yAxis.setStart(now / 1000 * 1000 - 9000); yAxis.setEnd(now / 1000 * 1000 + 1000); double y2 = now; double x2 = Math.sin(y2 / 2000.0); d.add(x2, y2); marker.setValue(x2); marker2.setValue(y2); } });
false
Plotter_src_examples_java_plotter_examples_ScrollingTimeOnY.java
1,970
public class SmoothScrolling { public static void main(String[] args) { final XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); Timer timer = new Timer(); final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis(); final XYAxis yAxis = frame.getYAxis(); xAxis.setTickMarkCalculator(new TimeTickMarkCalculator()); xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS"))); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); final XYMarkerLine marker = new XYMarkerLine(xAxis, 60); marker.setForeground(Color.yellow); XYPlotContents contents = frame.getContents(); contents.add(marker); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(10); frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>")); frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss} <b>&Delta;y:</b> {1}</html>")); for(int x = 0; x < 900; x++) { double x2 = x / 10.0; double y2 = Math.sin(x2 / 10.0); d.add(x2, y2); } timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now - 5000); xAxis.setEnd(now + 5000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); } }); } }, 100, 100); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_SmoothScrolling.java
1,971
timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now - 5000); xAxis.setEnd(now + 5000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); } }); } }, 100, 100);
false
Plotter_src_examples_java_plotter_examples_SmoothScrolling.java
1,972
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { long now = System.currentTimeMillis(); xAxis.setStart(now - 5000); xAxis.setEnd(now + 5000); double x2 = now; double y2 = Math.sin(x2 / 2000.0); d.add(x2, y2); marker.setValue(x2); } });
false
Plotter_src_examples_java_plotter_examples_SmoothScrolling.java
1,973
public class Static { public static void main(String[] args) { XYPlotFrame frame = new XYPlotFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setup(); XYAxis xAxis = frame.getXAxis(); XYAxis yAxis = frame.getYAxis(); final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); frame.addPlotLine(line); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(2 * Math.PI); for(int x = 0; x <= 100; x++) { double x2 = x / 100.0 * 2 * Math.PI; double y2 = Math.sin(x2); d.add(x2, y2); } frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_Static.java
1,974
public class StressTest { public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); int plotsx = 32; int plotsy = 32; final int linesPerPlot = 2; JPanel container = new JPanel(); container.setLayout(new GridLayout(plotsx, plotsy)); contentPane.add(new JScrollPane(container)); Timer timer = new Timer(); final int numPlots = plotsx * plotsy; final Axis[] xAxes = new Axis[numPlots]; final Axis[] yAxes = new Axis[numPlots]; final SimpleXYDataset[][] datasets = new SimpleXYDataset[numPlots][linesPerPlot]; SlopeLine slopeLine = new SlopeLine(); slopeLine.setForeground(Color.white); for(int i = 0; i < numPlots; i++) { final XYPlot plot = new XYPlot(); final XYAxis xAxis = new LinearXYAxis(XYDimension.X); final XYAxis yAxis = new LinearXYAxis(XYDimension.Y); xAxis.setPreferredSize(new Dimension(1, 30)); yAxis.setPreferredSize(new Dimension(40, 1)); xAxis.setForeground(Color.white); yAxis.setForeground(Color.white); xAxis.setTextMargin(10); yAxis.setTextMargin(10); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); plot.setBackground(Color.darkGray); XYGrid grid = new XYGrid(xAxis, yAxis); grid.setForeground(Color.lightGray); XYPlotContents contents = new XYPlotContents(); contents.setBackground(Color.black); plot.add(contents); contents.add(grid); plot.setPreferredSize(new Dimension(150, 100)); new DefaultXYLayoutGenerator().generateLayout(plot); for(int j = 0; j < linesPerPlot; j++) { final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X); line.setForeground(Color.white); final SimpleXYDataset d = new SimpleXYDataset(line); d.setMaxCapacity(1000); d.setXData(line.getXData()); d.setYData(line.getYData()); contents.add(line); for(int x = 0; x < 900; x++) { double x2 = x / 10.0; double y2 = Math.sin(x2 / 10.0 + Math.PI * j / (double) linesPerPlot); d.add(x2, y2); } datasets[i][j] = d; } slopeLine.attach(plot); yAxis.setStart(-1.2); yAxis.setEnd(1.2); xAxis.setStart(0); xAxis.setEnd(10); container.add(plot); xAxes[i] = xAxis; yAxes[i] = yAxis; System.out.println("Plot " + (i + 1) + " of " + numPlots + " created"); } timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for(int i = 0; i < numPlots; i++) { xAxes[i].setStart(x / 10); xAxes[i].setEnd(x / 10 + 100); for(int j = 0; j < linesPerPlot; j++) { double x2 = x / 10.0 + 90; double y2 = Math.sin(x2 / 10.0 + Math.PI * j / (double) linesPerPlot); datasets[i][j].add(x2, y2); } } } }); } }, 1000, 1000); frame.setSize(400, 300); frame.setVisible(true); } }
false
Plotter_src_examples_java_plotter_examples_StressTest.java
1,975
timer.schedule(new TimerTask() { int x = 0; @Override public void run() { x++; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for(int i = 0; i < numPlots; i++) { xAxes[i].setStart(x / 10); xAxes[i].setEnd(x / 10 + 100); for(int j = 0; j < linesPerPlot; j++) { double x2 = x / 10.0 + 90; double y2 = Math.sin(x2 / 10.0 + Math.PI * j / (double) linesPerPlot); datasets[i][j].add(x2, y2); } } } }); } }, 1000, 1000);
false
Plotter_src_examples_java_plotter_examples_StressTest.java
1,976
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { for(int i = 0; i < numPlots; i++) { xAxes[i].setStart(x / 10); xAxes[i].setEnd(x / 10 + 100); for(int j = 0; j < linesPerPlot; j++) { double x2 = x / 10.0 + 90; double y2 = Math.sin(x2 / 10.0 + Math.PI * j / (double) linesPerPlot); datasets[i][j].add(x2, y2); } } } });
false
Plotter_src_examples_java_plotter_examples_StressTest.java
1,977
public class XYPlotFrame extends JFrame { private static final long serialVersionUID = 1L; private XYPlot plot; private XYAxis xAxis; private XYAxis yAxis; private XYGrid grid; private XYPlotContents contents; private XYLocationDisplay locationDisplay; private SlopeLineDisplay slopeLineDisplay; public void setup() { Container contentPane = getContentPane(); plot = new XYPlot(); xAxis = createXAxis(); yAxis = createYAxis(); xAxis.setPreferredSize(new Dimension(1, 40)); yAxis.setPreferredSize(new Dimension(40, 1)); xAxis.setForeground(Color.white); yAxis.setForeground(Color.white); xAxis.setTextMargin(10); yAxis.setTextMargin(10); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); plot.setBackground(Color.darkGray); contents = new XYPlotContents(); contents.setBackground(Color.black); plot.setBackground(Color.darkGray); grid = new XYGrid(xAxis, yAxis); grid.setForeground(Color.lightGray); contents.add(grid); plot.add(contents); plot.setPreferredSize(new Dimension(150, 100)); contentPane.setBackground(Color.darkGray); locationDisplay = new XYLocationDisplay(); // This is a hack to set the preferred height to the normal height so the component doesn't collapse to height 0 when the text is empty. // Note that mimimumSize does not work for some reason. locationDisplay.setText("Ag"); Dimension size = locationDisplay.getPreferredSize(); size.width = 100; locationDisplay.setText(""); locationDisplay.setPreferredSize(size); // End hack locationDisplay.setForeground(Color.white); locationDisplay.setFont(new Font("Arial", 0, 12)); locationDisplay.setFormat(new MessageFormat("<html><b>X:</b> {0} &nbsp; <b>Y:</b> {1}</html>")); locationDisplay.attach(plot); plot.add(locationDisplay); SlopeLine slopeLine = new SlopeLine(); slopeLine.setForeground(Color.white); slopeLine.attach(plot); slopeLineDisplay = new SlopeLineDisplay(); slopeLine.addListenerForPlot(plot, slopeLineDisplay); slopeLineDisplay.setFont(new Font("Arial", 0, 12)); slopeLineDisplay.setForeground(Color.white); slopeLineDisplay.setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0} <b>&Delta;y:</b> {1}</html>")); plot.add(slopeLineDisplay); new DefaultXYLayoutGenerator().generateLayout(plot); SpringLayout layout2 = (SpringLayout) plot.getLayout(); layout2.putConstraint(SpringLayout.NORTH, locationDisplay, 0, SpringLayout.NORTH, plot); layout2.putConstraint(SpringLayout.WEST, locationDisplay, 0, SpringLayout.WEST, contents); layout2.putConstraint(SpringLayout.EAST, locationDisplay, 0, SpringLayout.HORIZONTAL_CENTER, contents); layout2.putConstraint(SpringLayout.NORTH, contents, 0, SpringLayout.SOUTH, locationDisplay); layout2.putConstraint(SpringLayout.NORTH, slopeLineDisplay, 0, SpringLayout.NORTH, plot); layout2.putConstraint(SpringLayout.WEST, slopeLineDisplay, 0, SpringLayout.HORIZONTAL_CENTER, contents); layout2.putConstraint(SpringLayout.EAST, slopeLineDisplay, 0, SpringLayout.EAST, contents); yAxis.setEndMargin((int) locationDisplay.getPreferredSize().getHeight()); SpringLayout layout = new SpringLayout(); contentPane.setLayout(layout); layout.putConstraint(SpringLayout.NORTH, plot, 0, SpringLayout.NORTH, contentPane); layout.putConstraint(SpringLayout.SOUTH, contentPane, 0, SpringLayout.SOUTH, plot); layout.putConstraint(SpringLayout.EAST, contentPane, 0, SpringLayout.EAST, plot); contentPane.add(plot); } protected XYAxis createYAxis() { return new LinearXYAxis(XYDimension.Y); } protected XYAxis createXAxis() { return new LinearXYAxis(XYDimension.X); } public void addPlotLine(JComponent plotLine) { contents.add(plotLine); contents.setComponentZOrder(grid, contents.getComponentCount() - 1); } public XYAxis getXAxis() { return xAxis; } public XYAxis getYAxis() { return yAxis; } public XYPlotContents getContents() { return contents; } public XYLocationDisplay getLocationDisplay() { return locationDisplay; } public SlopeLineDisplay getSlopeLineDisplay() { return slopeLineDisplay; } public XYPlot getPlot() { return plot; } }
false
Plotter_src_examples_java_plotter_examples_XYPlotFrame.java
1,978
public class JUnitInternal extends TestSuite { public static TestSuite suite() { TestSuite suite = new TestSuite("Plotter Internal"); suite.addTestSuite(JUnitRangeSet.class); return suite; } }
false
Plotter_src_test_java_plotter_internal_JUnitInternal.java
1,979
public class JUnitRangeSet extends TestCase { public void testGeneral() { RangeSet r = new RangeSet(); assertNull(r.getData()); assertEquals(Double.POSITIVE_INFINITY, r.getMin()); assertEquals(Double.NEGATIVE_INFINITY, r.getMax()); r.add(1, 2); assertNull(r.getData()); assertEquals(1.0, r.getMin()); assertEquals(2.0, r.getMax()); r.add(3, 4); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(1.0, 2.0); m.put(3.0, 4.0); assertEquals(m, r.getData()); } public void testOverlap1() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(.5, 1.5); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(.5, 2.0); m.put(3.0, 4.0); assertEquals(m, r.getData()); } public void testOverlap2() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(.5, 2.5); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(.5, 2.5); m.put(3.0, 4.0); assertEquals(m, r.getData()); } public void testOverlap3() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(.5, 3.5); assertNull(r.getData()); assertEquals(.5, r.getMin()); assertEquals(4.0, r.getMax()); } public void testOverlap4() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(.5, 4.5); assertNull(r.getData()); assertEquals(.5, r.getMin()); assertEquals(4.5, r.getMax()); } public void testOverlap5() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(1.5, 1.75); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(1.0, 2.0); m.put(3.0, 4.0); assertEquals(m, r.getData()); } public void testOverlap6() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(1.5, 2.5); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(1.0, 2.5); m.put(3.0, 4.0); assertEquals(m, r.getData()); } public void testOverlap7() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(1.5, 3.5); assertNull(r.getData()); assertEquals(1.0, r.getMin()); assertEquals(4.0, r.getMax()); } public void testOverlap8() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(1.5, 4.5); assertNull(r.getData()); assertEquals(1.0, r.getMin()); assertEquals(4.5, r.getMax()); } public void testOverlapMultiple1() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(5, 6); r.add(1.5, 5.5); assertNull(r.getData()); assertEquals(1.0, r.getMin()); assertEquals(6.0, r.getMax()); } public void testOverlapMultiple2() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(5, 6); r.add(7, 8); r.add(1.5, 5.5); Map<Double, Double> m = new HashMap<Double, Double>(); m.put(1.0, 6.0); m.put(7.0, 8.0); assertEquals(m, r.getData()); } public void testToStringEmpty() { RangeSet r = new RangeSet(); assertEquals("{}", r.toString()); } public void testToStringOne() { RangeSet r = new RangeSet(); r.add(1, 2); assertEquals("{(1.0:2.0)}", r.toString()); } public void testToStringMany() { RangeSet r = new RangeSet(); r.add(1, 2); r.add(3, 4); r.add(5, 6); assertEquals("{(1.0:2.0),(3.0:4.0),(5.0:6.0)}", r.toString()); } }
false
Plotter_src_test_java_plotter_internal_JUnitRangeSet.java
1,980
public class RangeSet { /** Holds the minimum value if there is exactly one range, infinity if none, and is undefined otherwise. */ private double min = Double.POSITIVE_INFINITY; /** Holds the maximum value if there is exactly one range, negative infinity if none, and is undefined otherwise. */ private double max = Double.NEGATIVE_INFINITY; /** If there is more than one range, this maps the minimum to the maximum for each range. Otherwise, this is null. */ private NavigableMap<Double, Double> data; /** * Unions the range set with the range (min, max). * Min and max are inclusive. * @param min minimum endpoint of the range * @param max maximum endpoint of the range */ public void add(double min, double max) { if(data != null) { Entry<Double, Double> e = data.floorEntry(min); if(e != null) { double key = e.getKey(); double value = e.getValue(); if(min <= value && max >= key) { min = Math.min(key, min); max = Math.max(value, max); data.remove(key); } } do { Entry<Double, Double> e2 = data.higherEntry(min); if(e2 == null) { break; } double key = e2.getKey(); double value = e2.getValue(); if(!(min <= value && max >= key)) { break; } min = Math.min(key, min); max = Math.max(value, max); data.remove(key); } while(true); if(data.isEmpty()) { data = null; this.min = min; this.max = max; } else { data.put(min, max); } } else if((this.min == Double.POSITIVE_INFINITY && this.max == Double.NEGATIVE_INFINITY) || (min <= this.max && max >= this.min)) { this.min = Math.min(this.min, min); this.max = Math.max(this.max, max); } else { data = new TreeMap<Double, Double>(); data.put(this.min, this.max); data.put(min, max); } } /** * Resets this to the empty set. */ public void clear() { min = Double.POSITIVE_INFINITY; max = Double.NEGATIVE_INFINITY; data = null; } /** * Returns the minimum value if there is exactly one range, infinity if none, and an unspecified value otherwise. * @return the minimum value */ public double getMin() { return min; } /** * Returns the maximum value if there is exactly one range, infinity if none, and an unspecified value otherwise. * @return the maximum value */ public double getMax() { return max; } /** * Returns a map of the minimum to the maximum for each range, or null if there are zero or one ranges. * @return a map of the minimum to the maximum for each range, may be null */ public NavigableMap<Double, Double> getData() { return data; } @Override public String toString() { if(data == null) { if(min == Double.POSITIVE_INFINITY) { return "{}"; } else { return "{(" + min + ":" + max + ")}"; } } else { StringBuffer b = new StringBuffer(); b.append("{"); for(Iterator<Entry<Double, Double>> itr = data.entrySet().iterator(); itr.hasNext();) { Entry<Double, Double> e = itr.next(); double min = e.getKey(); double max = e.getValue(); b.append("("); b.append(min); b.append(":"); b.append(max); b.append(")"); if(itr.hasNext()) { b.append(","); } } b.append("}"); return b.toString(); } } }
false
Plotter_src_main_java_plotter_internal_RangeSet.java
1,981
public class CompressingXYDataset implements XYDataset { /** Plot line that displays the data. */ private LinearXYPlotLine line; /** Holds the X data. */ private DoubleData xData; /** Holds the Y data. */ private DoubleData yData; /** * Points under this value will be truncated. * @see #truncationOffset */ private double truncationPoint = Double.NEGATIVE_INFINITY; /** When truncating, this many points will be kept that are under {@link #truncationPoint}. */ private int truncationOffset = 1; /** Cached minimum X value of all points in the dataset. */ private double minX = Double.POSITIVE_INFINITY; /** Cached maximum X value of all points in the dataset. */ private double maxX = Double.NEGATIVE_INFINITY; /** Cached minimum Y value of all points in the dataset. */ private double minY = Double.POSITIVE_INFINITY; /** Cached maximum Y value of all points in the dataset. */ private double maxY = Double.NEGATIVE_INFINITY; /** Listeners that get notified if the X min or max changes. May be null. */ private Set<MinMaxChangeListener> xMinMaxListeners; /** Listeners that get notified if the Y min or max chagnes. May be null. */ private Set<MinMaxChangeListener> yMinMaxListeners; /** Value of {@link #minX} before a modification. */ private double oldMinX; /** Value of {@link #maxX} before a modification. */ private double oldMaxX; /** Value of {@link #minY} before a modification. */ private double oldMinY; /** Value of {@link #maxX} before a modification. */ private double oldMaxY; /** Performs the compression. */ private Compressor compressor; /** Performs the streaming compression. */ private StreamingCompressor streamingCompressor; /** Offset to use for compression. */ private double compressionOffset; /** Scale to use for compression. */ private double compressionScale; /** * Creates a dataset. * @param line line to plot the data * @param compressor performs the compression */ public CompressingXYDataset(LinearXYPlotLine line, Compressor compressor) { if(line.getIndependentDimension() == null) { throw new IllegalArgumentException("Can't use CompressingXYDataset with a scatter plot"); } this.line = line; this.compressor = compressor; xData = line.getXData(); yData = line.getYData(); } /** * Adds a point, truncating the buffer if necessary. * For the independent dimension, the coordinate must be must be greater than or equal to all other values in the dataset for that dimension. * @param x the X coordinate * @param y the Y coordinate */ @Override public void add(double x, double y) { preMod(); truncate(); if(streamingCompressor == null) { XYDataset out; if(line.getIndependentDimension() == XYDimension.X) { out = line; } else { out = new XYReversingDataset(line); } streamingCompressor = compressor.createStreamingCompressor(out, compressionOffset, compressionScale); } int updateSize; if(line.getIndependentDimension() == XYDimension.X) { updateSize = streamingCompressor.add(x, y); } else { updateSize = streamingCompressor.add(y, x); } updateMinMax(x, y); postMod(); } /** * Called after a modification. * Notifies any relevant listeners of changes. */ protected void postMod() { if(xMinMaxListeners != null) { if(minX != oldMinX || maxX != oldMaxX) { for(MinMaxChangeListener listener : xMinMaxListeners) { listener.minMaxChanged(this, XYDimension.X); } } } if(yMinMaxListeners != null) { if(minY != oldMinY || maxY != oldMaxY) { for(MinMaxChangeListener listener : yMinMaxListeners) { listener.minMaxChanged(this, XYDimension.Y); } } } } /** * Called before a modification. * Stores any state needed for {@link #postMod()}. */ protected void preMod() { oldMinX = minX; oldMaxX = maxX; oldMinY = minY; oldMaxY = maxY; } private void truncate() { DoubleData data = line.getIndependentDimension() == XYDimension.Y ? yData : xData; int length = data.getLength(); // We assume here that not many points will be truncated, so a simple linear search is best. // If a large number of points may be truncated, a binary search may be better. int i = 0; while(i < length && data.get(i) < truncationPoint) { i++; } i -= truncationOffset; if(i > 0) { _removeFirst(i); } } /** * Removes the first <code>removeCount</code> points from the dataset. * Does not call {@link #preMod()} or {@link #postMod()}. * @param removeCount number of points to remove */ private void _removeFirst(int removeCount) { // TODO: Use a more efficient method than rescanning the entire arrays. For example, cache min/max values for subranges. int length = xData.getLength(); boolean rescanX = false; boolean rescanY = false; for(int i = 0; i < removeCount; i++) { double xd = xData.get(i); double yd = yData.get(i); if(xd == minX || xd == maxX) { rescanX = true; } if(yd == minY || yd == maxY) { rescanY = true; } } XYDimension independentDimension = line.getIndependentDimension(); if(rescanX) { if(independentDimension == XYDimension.X) { if(removeCount < length) { minX = xData.get(removeCount); maxX = xData.get(length - 1); } else { minX = Double.POSITIVE_INFINITY; maxX = Double.NEGATIVE_INFINITY; } } else { minX = Double.POSITIVE_INFINITY; maxX = Double.NEGATIVE_INFINITY; for(int i = removeCount; i < length; i++) { double xd = xData.get(i); if(xd > maxX) { maxX = xd; } if(xd < minX) { minX = xd; } } } } if(rescanY) { if(independentDimension == XYDimension.Y) { if(removeCount < length) { minY = yData.get(removeCount); maxY = yData.get(length - 1); } else { minY = Double.POSITIVE_INFINITY; maxY = Double.NEGATIVE_INFINITY; } } else { minY = Double.POSITIVE_INFINITY; maxY = Double.NEGATIVE_INFINITY; for(int i = removeCount; i < length; i++) { double yd = yData.get(i); if(yd > maxY) { maxY = yd; } if(yd < minY) { minY = yd; } } } } line.removeFirst(removeCount); } @Override public void prepend(double[] x, int xoff, double[] y, int yoff, int len) { preMod(); PointData input = new PointData(); XYDimension independentDimension = line.getIndependentDimension(); if(independentDimension == XYDimension.X) { input.getX().add(x, xoff, len); input.getY().add(y, yoff, len); } else { input.getY().add(x, xoff, len); input.getX().add(y, yoff, len); } PointData output = new PointData(); compressor.compress(input, output, compressionOffset, compressionScale); DoubleData outx; DoubleData outy; if(independentDimension == XYDimension.X) { outx = output.getX(); outy = output.getY(); } else { outy = output.getX(); outx = output.getY(); } for(int i = 0; i < len; i++) { updateMinMax(x[xoff + i], y[yoff + i]); } // TODO: Only add data that wouldn't be truncated line.prepend(outx, outy); postMod(); } @Override public void prepend(DoubleData x, DoubleData y) { preMod(); PointData input = new PointData(x, y); PointData output = new PointData(); compressor.compress(input, output, compressionOffset, compressionScale); DoubleData outx; DoubleData outy; XYDimension independentDimension = line.getIndependentDimension(); if(independentDimension == XYDimension.X) { outx = output.getX(); outy = output.getY(); } else { outy = output.getX(); outx = output.getY(); } int length = outx.getLength(); for(int i = 0; i < length; i++) { updateMinMax(outx.get(i), outy.get(i)); } // TODO: Only add data that wouldn't be truncated line.prepend(outx, outy); postMod(); } /** * Updates the min/max cache to include this point. * @param x X coordinate * @param y Y coordinate */ private void updateMinMax(double x, double y) { if(x > maxX) { maxX = x; } if(x < minX) { minX = x; } if(y > maxY) { maxY = y; } if(y < minY) { minY = y; } } @Override public void removeAllPoints() { preMod(); line.removeAllPoints(); minX = Double.POSITIVE_INFINITY; maxX = Double.NEGATIVE_INFINITY; minY = Double.POSITIVE_INFINITY; maxY = Double.NEGATIVE_INFINITY; postMod(); } /** * Recompresses the existing data. * This is useful if the compression scale has increased since data was added. * Data may lose fidelity if compressed multiple times. */ public void recompress() { DoubleData newx =xData.clone(); DoubleData newy =yData.clone(); line.removeAllPoints(); prepend(newx, newy); } @Override public int getPointCount() { return xData.getLength(); } /** * Returns the X data. * @return the X data */ public DoubleData getXData() { return xData; } /** * Sets the X data. * @param xData the X data */ public void setXData(DoubleData xData) { this.xData = xData; } /** * Returns the Y data. * @return the Y data */ public DoubleData getYData() { return yData; } /** * Sets the Y data. * @param yData the Y data */ public void setYData(DoubleData yData) { this.yData = yData; } /** * Returns the truncation point. * @return the truncation point */ public double getTruncationPoint() { return truncationPoint; } /** * Sets the truncation point. * @param truncationPoint the truncation point */ public void setTruncationPoint(double truncationPoint) { this.truncationPoint = truncationPoint; } /** * Returns the truncation offset. * @return the truncation offset */ public int getTruncationOffset() { return truncationOffset; } /** * Sets the truncation offset. * @param truncationOffset the truncation offset */ public void setTruncationOffset(int truncationOffset) { this.truncationOffset = truncationOffset; } /** * Returns the compression offset. * @return the compression offset */ public double getCompressionOffset() { return compressionOffset; } /** * Sets the compression offset. * @param compressionOffset the compression offset */ public void setCompressionOffset(double compressionOffset) { assert !Double.isNaN(compressionOffset); assert !Double.isInfinite(compressionOffset); if(this.compressionOffset != compressionOffset) { this.compressionOffset = compressionOffset; streamingCompressor = null; } } /** * Returns the compression scale. * @return the compression scale */ public double getCompressionScale() { return compressionScale; } /** * Sets the compression scale. * @param compressionScale the compression scale */ public void setCompressionScale(double compressionScale) { assert !Double.isNaN(compressionScale) : "Scale cannot be NaN"; assert !Double.isInfinite(compressionScale) : "Scale cannot be infinite"; if(this.compressionScale != compressionScale) { this.compressionScale = compressionScale; streamingCompressor = null; } } /** * Returns the minimum X value. * @return the minimum X value */ public double getMinX() { return minX; } /** * Returns the maximum X value. * @return the maximum X value */ public double getMaxX() { return maxX; } /** * Returns the minimum Y value. * @return the minimum Y value */ public double getMinY() { return minY; } /** * Returns the maximum Y value. * @return the maximum Y value */ public double getMaxY() { return maxY; } /** * Adds a listener for min/max changes to the X data. * @param listener listener to add */ public void addXMinMaxChangeListener(MinMaxChangeListener listener) { if(xMinMaxListeners == null) { xMinMaxListeners = new HashSet<MinMaxChangeListener>(); } xMinMaxListeners.add(listener); } /** * Adds a listener for min/max changes to the Y data. * @param listener listener to add */ public void addYMinMaxChangeListener(MinMaxChangeListener listener) { if(yMinMaxListeners == null) { yMinMaxListeners = new HashSet<MinMaxChangeListener>(); } yMinMaxListeners.add(listener); } /** * Removes all {@link MinMaxChangeListener}s for the Y data. */ public void removeAllYMinMaxChangeListeners() { yMinMaxListeners = null; } /** * Removes all {@link MinMaxChangeListener}s for the X data. */ public void removeAllXMinMaxChangeListeners() { xMinMaxListeners = null; } /** * Note that this may not behave as expected. * In particular, removing as many points as you added will not work, * because the added points may have been compressed into a smaller number. */ @Override public void removeLast(int count) { line.removeLast(count); } /** * Listens to min/max changes. * @author Adam Crume */ public interface MinMaxChangeListener { /** * Notifies the listener that the min or max changed. * @param dataset dataset containing the data * @param dimension specifies whether this notification is for the X or Y data */ public void minMaxChanged(CompressingXYDataset dataset, XYDimension dimension); } }
false
Plotter_src_main_java_plotter_xy_CompressingXYDataset.java
1,982
public interface MinMaxChangeListener { /** * Notifies the listener that the min or max changed. * @param dataset dataset containing the data * @param dimension specifies whether this notification is for the X or Y data */ public void minMaxChanged(CompressingXYDataset dataset, XYDimension dimension); }
false
Plotter_src_main_java_plotter_xy_CompressingXYDataset.java
1,983
public interface CompressionOutput { /** * Adds a data point. * @param x the X-coordinate of the data point * @param y the Y-coordinate of the data point */ public void add(double x, double y); /** * Returns the number of data points. * @return the number of data points */ public int getPointCount(); /** * Removes the last <code>count</code> data points. * @param count number of data points to remove */ public void removeLast(int count); }
false
Plotter_src_main_java_plotter_xy_CompressionOutput.java
1,984
public interface Compressor { /** * Compresses a set of data. * Note that in the input and output, X is assumed to be the independent dimension. * @param input data to compress * @param output receives the compressed data * @param offset logical coordinate of the first pixel * @param scale width of a pixel, in logical units */ public void compress(PointData input, PointData output, double offset, double scale); /** * Creates a streaming compressor. * Note that in the output, X is assumed to be the independent dimension. * @param output receives the compressed data * @param offset logical coordinate of the first pixel * @param scale width of a pixel, in logical units * @return new streaming compressor */ public StreamingCompressor createStreamingCompressor(CompressionOutput output, double offset, double scale); /** * Compresses streaming data. * A varying number of points at the end of the output is considered work in progress. * These points may be removed or modified by the {@link #add(double, double)} method, not just added. * Modifying these points directly (or changing the size of the output) may result in undefined behavior. */ public interface StreamingCompressor { /** * Adds a data point to the end. * Returns the number of points at the end of the output that were added or modified. * The size of the work in progress area is less than or equal to this number. * Modifying the work in progress area directly (or changing the size of the output) may result in undefined behavior. * @param independentValue coordinate of the point along the independent dimension * @param dependentValue coordinate of the point along the dependent dimension * @return number of points at the end of the output that were modified */ public int add(double independentValue, double dependentValue); } }
false
Plotter_src_main_java_plotter_xy_Compressor.java
1,985
public interface StreamingCompressor { /** * Adds a data point to the end. * Returns the number of points at the end of the output that were added or modified. * The size of the work in progress area is less than or equal to this number. * Modifying the work in progress area directly (or changing the size of the output) may result in undefined behavior. * @param independentValue coordinate of the point along the independent dimension * @param dependentValue coordinate of the point along the dependent dimension * @return number of points at the end of the output that were modified */ public int add(double independentValue, double dependentValue); }
false
Plotter_src_main_java_plotter_xy_Compressor.java
1,986
public class DefaultCompressor implements Compressor { @Override public void compress(PointData input, PointData output, double offset, double scale) { assert !Double.isNaN(offset); assert !Double.isInfinite(offset); assert !Double.isNaN(scale); assert !Double.isInfinite(scale); assert scale != 0; DoubleData inx = input.getX(); DoubleData iny = input.getY(); int size = inx.getLength(); if(size == 0) { return; } long bucket = (long) ((inx.get(0) - offset) / scale); double nextx = (bucket + 1) * scale + offset; int i = 0; double oldy = Double.NaN; RangeSet r = new RangeSet(); long bucketSize = 0; double firsty = Double.NaN; while(true) { double x = inx.get(i); double y = iny.get(i); if(x >= nextx) { double bucketx = bucket * scale + offset; flushBucket(output, bucketx, firsty, r, oldy, bucketSize); r.clear(); bucket = (int) ((x - offset) / scale); nextx = (bucket + 1) * scale + offset; bucketSize = 0; firsty = y; if(!Double.isNaN(y)) { r.add(y, y); } } else { if(bucketSize == 0) { firsty = y; } if(!Double.isNaN(y)) { if(Double.isNaN(oldy)) { r.add(y, y); } else { double min, max; if(oldy > y) { max = oldy; min = y; } else { max = y; min = oldy; } r.add(min, max); } } } oldy = y; i++; bucketSize++; if(i >= size) { double bucketx = bucket * scale + offset; flushBucket(output, bucketx, firsty, r, oldy, bucketSize); return; } } } private void flushBucket(CompressionOutput out, double bucketx, double firsty, RangeSet r, double lasty, long bucketSize) { out.add(bucketx, firsty); double prevy = firsty; NavigableMap<Double, Double> data2 = r.getData(); if(data2 == null) { double min = r.getMin(); double max = r.getMax(); if(min != Double.POSITIVE_INFINITY) { boolean wroteMin = false; // Since we always draw the first and last, it would be redundant to draw the min or max if it is equal to either. if(!(min == firsty || min == lasty)) { out.add(bucketx, min); prevy = min; wroteMin = true; } if(!(max == firsty || max == lasty || (wroteMin && max == min))) { out.add(bucketx, max); prevy = max; } } else if(bucketSize > 1 && !Double.isNaN(lasty) && !Double.isNaN(firsty)) { out.add(bucketx, Double.NaN); prevy = Double.NaN; } } else { boolean first = true; NavigableMap<Double, Double> m = data2; if(firsty > lasty) { // If the line is descending (based on the first and last Y coordinates), // draw the segments in decreasing order. This improves the odds that // we will be able to merge the first and last points into line segments. m = data2.descendingMap(); } for(Iterator<Entry<Double, Double>> itr = m.entrySet().iterator(); itr.hasNext();) { Entry<Double, Double> e = itr.next(); double min = e.getKey(); double max = e.getValue(); boolean last = !itr.hasNext(); boolean wroteSomething = true; // Since RangeSet will not return a map if there is only one segment, the current segment cannot be first and last. if(first) { if(firsty > max || firsty < min) { out.add(bucketx, Double.NaN); prevy = Double.NaN; } boolean wroteMin = false; if(!(min == firsty)) { out.add(bucketx, min); prevy = min; wroteMin = true; } if(!(max == firsty || (wroteMin && min == max))) { out.add(bucketx, max); prevy = max; } } else if(last) { boolean wroteMin = false; if(!(min == lasty)) { out.add(bucketx, min); prevy = min; wroteMin = true; } if(!(max == lasty || (wroteMin && min == max))) { out.add(bucketx, max); prevy = max; } } else { if(min == max) { if(!(min == firsty || min == lasty)) { out.add(bucketx, min); prevy = min; } else { wroteSomething = false; } } else { out.add(bucketx, min); out.add(bucketx, max); prevy = max; } } if(wroteSomething) { if(!last || lasty < min || lasty > max) { out.add(bucketx, Double.NaN); prevy = Double.NaN; } } first = false; } } if(!equal(lasty, prevy)) { out.add(bucketx, lasty); } } private static boolean equal(double a, double b) { return a == b || (Double.isNaN(a) && Double.isNaN(b)); } @Override public StreamingCompressor createStreamingCompressor(CompressionOutput output, double offset, double scale) { assert !Double.isNaN(offset) : "Offset cannot be NaN"; assert !Double.isInfinite(offset) : "Offset cannot be infinite"; assert !Double.isNaN(scale) : "Scale cannot be NaN"; assert !Double.isInfinite(scale) : "Scale cannot be infinite"; assert scale != 0 : "Scale cannot be zero"; return new DefaultStreamingCompressor(output, offset, scale); } /** * Default implementation of {@link Compressor.StreamingCompressor}. * @author Adam Crume */ public class DefaultStreamingCompressor implements StreamingCompressor { private CompressionOutput out; private double oldy = Double.NaN; private RangeSet r = new RangeSet(); private long bucketSize; private double nextx; private double firsty; private long bucket; private boolean first = true; private double offset; private double scale; private int tmpPoints; /** * Creates a streaming compressor. * @param out receives the compressed data * @param offset compression offset * @param scale compression scale */ public DefaultStreamingCompressor(CompressionOutput out, double offset, double scale) { this.out = out; this.offset = offset; this.scale = scale; } @Override public int add(double x, double y) { if(first) { bucket = (long) ((x - offset) / scale); nextx = (bucket + 1) * scale + offset; first = false; } out.removeLast(tmpPoints); int sizeBeforeModification = out.getPointCount(); if(x >= nextx) { double bucketx = bucket * scale + offset; flushBucket(out, bucketx, firsty, r, oldy, bucketSize); r.clear(); bucket = (int) ((x - offset) / scale); nextx = (bucket + 1) * scale + offset; bucketSize = 0; firsty = y; if(!Double.isNaN(y)) { r.add(y, y); } } else { if(bucketSize == 0) { firsty = y; } if(!Double.isNaN(y)) { if(Double.isNaN(oldy)) { r.add(y, y); } else { double min, max; if(oldy > y) { max = oldy; min = y; } else { max = y; min = oldy; } r.add(min, max); } } } oldy = y; bucketSize++; int sizeWithoutTempArea = out.getPointCount(); double bucketx = bucket * scale + offset; flushBucket(out, bucketx, firsty, r, y, bucketSize); tmpPoints = out.getPointCount() - sizeWithoutTempArea; return out.getPointCount() - sizeBeforeModification; } } }
false
Plotter_src_main_java_plotter_xy_DefaultCompressor.java
1,987
public class DefaultStreamingCompressor implements StreamingCompressor { private CompressionOutput out; private double oldy = Double.NaN; private RangeSet r = new RangeSet(); private long bucketSize; private double nextx; private double firsty; private long bucket; private boolean first = true; private double offset; private double scale; private int tmpPoints; /** * Creates a streaming compressor. * @param out receives the compressed data * @param offset compression offset * @param scale compression scale */ public DefaultStreamingCompressor(CompressionOutput out, double offset, double scale) { this.out = out; this.offset = offset; this.scale = scale; } @Override public int add(double x, double y) { if(first) { bucket = (long) ((x - offset) / scale); nextx = (bucket + 1) * scale + offset; first = false; } out.removeLast(tmpPoints); int sizeBeforeModification = out.getPointCount(); if(x >= nextx) { double bucketx = bucket * scale + offset; flushBucket(out, bucketx, firsty, r, oldy, bucketSize); r.clear(); bucket = (int) ((x - offset) / scale); nextx = (bucket + 1) * scale + offset; bucketSize = 0; firsty = y; if(!Double.isNaN(y)) { r.add(y, y); } } else { if(bucketSize == 0) { firsty = y; } if(!Double.isNaN(y)) { if(Double.isNaN(oldy)) { r.add(y, y); } else { double min, max; if(oldy > y) { max = oldy; min = y; } else { max = y; min = oldy; } r.add(min, max); } } } oldy = y; bucketSize++; int sizeWithoutTempArea = out.getPointCount(); double bucketx = bucket * scale + offset; flushBucket(out, bucketx, firsty, r, y, bucketSize); tmpPoints = out.getPointCount() - sizeWithoutTempArea; return out.getPointCount() - sizeBeforeModification; } }
false
Plotter_src_main_java_plotter_xy_DefaultCompressor.java
1,988
public class DefaultXYLayoutGenerator { /** * Sets up the layout for the plot. * Note that the constraints for some children may be affected by the existence of certain other children. * @param plot plot to lay out */ public void generateLayout(XYPlot plot) { SpringLayout layout = new SpringLayout(); plot.setLayout(layout); XYAxis xAxis = null; XYAxis yAxis = null; XYPlotContents contents = null; XYLocationDisplay locationDisplay = null; SlopeLineDisplay slopeDisplay = null; for(Component c : plot.getComponents()) { if(c instanceof XYPlotContents) { contents = (XYPlotContents) c; layout.putConstraint(SpringLayout.EAST, c, 0, SpringLayout.EAST, plot); } else if(c instanceof XYAxis) { XYAxis a = (XYAxis) c; if(a.getPlotDimension() == XYDimension.X) { xAxis = a; layout.putConstraint(SpringLayout.SOUTH, c, 0, SpringLayout.SOUTH, plot); layout.putConstraint(SpringLayout.EAST, c, 0, SpringLayout.EAST, plot); } else { yAxis = a; layout.putConstraint(SpringLayout.WEST, c, 0, SpringLayout.WEST, plot); layout.putConstraint(SpringLayout.NORTH, c, 0, SpringLayout.NORTH, plot); } } else if(c instanceof XYLocationDisplay) { locationDisplay = (XYLocationDisplay) c; layout.putConstraint(SpringLayout.NORTH, c, 0, SpringLayout.NORTH, plot); } else if(c instanceof SlopeLineDisplay) { slopeDisplay = (SlopeLineDisplay) c; layout.putConstraint(SpringLayout.NORTH, c, 0, SpringLayout.NORTH, plot); } } if(contents != null) { if(locationDisplay != null) { layout.putConstraint(SpringLayout.WEST, locationDisplay, 0, SpringLayout.WEST, contents); layout.putConstraint(SpringLayout.EAST, locationDisplay, 0, SpringLayout.HORIZONTAL_CENTER, contents); } if(slopeDisplay != null) { layout.putConstraint(SpringLayout.WEST, slopeDisplay, 0, SpringLayout.HORIZONTAL_CENTER, contents); layout.putConstraint(SpringLayout.EAST, slopeDisplay, 0, SpringLayout.EAST, contents); } int margin; if(locationDisplay != null) { layout.putConstraint(SpringLayout.NORTH, contents, 0, SpringLayout.SOUTH, locationDisplay); margin = (int) locationDisplay.getPreferredSize().getHeight(); } else if(slopeDisplay != null) { layout.putConstraint(SpringLayout.NORTH, contents, 0, SpringLayout.SOUTH, slopeDisplay); margin = (int) slopeDisplay.getPreferredSize().getHeight(); } else { layout.putConstraint(SpringLayout.NORTH, contents, 0, SpringLayout.NORTH, plot); margin = 0; } if(xAxis != null) { layout.putConstraint(SpringLayout.SOUTH, contents, 0, SpringLayout.NORTH, xAxis); } else { layout.putConstraint(SpringLayout.SOUTH, contents, 0, SpringLayout.SOUTH, plot); } if(yAxis != null) { layout.putConstraint(SpringLayout.WEST, contents, 0, SpringLayout.EAST, yAxis); yAxis.setEndMargin(margin); } else { layout.putConstraint(SpringLayout.WEST, contents, 0, SpringLayout.WEST, plot); } } if(xAxis != null && yAxis != null) { xAxis.setStartMargin((int) yAxis.getPreferredSize().getWidth()); yAxis.setStartMargin((int) xAxis.getPreferredSize().getHeight()); layout.putConstraint(SpringLayout.WEST, xAxis, 0, SpringLayout.WEST, yAxis); layout.putConstraint(SpringLayout.SOUTH, yAxis, 0, SpringLayout.SOUTH, xAxis); } } }
false
Plotter_src_main_java_plotter_xy_DefaultXYLayoutGenerator.java
1,989
public class JUnitCompressingXYDataset extends TestCase { public void testPrepend() { CompressingXYDataset dataset = createDataset(XYDimension.X); double[] x = new double[] { .1, .2, .3, 1.1, 1.2 }; double[] y = new double[] { 2.1, 2.2, 2.3, 3.1, 3.2 }; dataset.prepend(x, 0, y, 0, x.length); DoubleData xData = dataset.getXData(); DoubleData yData = dataset.getYData(); assertEquals(4, xData.getLength()); assertEquals(4, yData.getLength()); assertEquals(0.0, xData.get(0)); assertEquals(2.1, yData.get(0)); assertEquals(0.0, xData.get(1)); assertEquals(2.3, yData.get(1)); assertEquals(1.0, xData.get(2)); assertEquals(3.1, yData.get(2)); assertEquals(1.0, xData.get(3)); assertEquals(3.2, yData.get(3)); assertEquals(.1, dataset.getMinX()); assertEquals(1.2, dataset.getMaxX()); assertEquals(2.1, dataset.getMinY()); assertEquals(3.2, dataset.getMaxY()); } public void testPrependYIndependent() { CompressingXYDataset dataset = createDataset(XYDimension.Y); double[] y = new double[] { .1, .2, .3, 1.1, 1.2 }; double[] x = new double[] { 2.1, 2.2, 2.3, 3.1, 3.2 }; dataset.prepend(x, 0, y, 0, x.length); DoubleData xData = dataset.getXData(); DoubleData yData = dataset.getYData(); assertEquals(4, yData.getLength()); assertEquals(4, xData.getLength()); assertEquals(0.0, yData.get(0)); assertEquals(2.1, xData.get(0)); assertEquals(0.0, yData.get(1)); assertEquals(2.3, xData.get(1)); assertEquals(1.0, yData.get(2)); assertEquals(3.1, xData.get(2)); assertEquals(1.0, yData.get(3)); assertEquals(3.2, xData.get(3)); assertEquals(.1, dataset.getMinY()); assertEquals(1.2, dataset.getMaxY()); assertEquals(2.1, dataset.getMinX()); assertEquals(3.2, dataset.getMaxX()); } public void testAdd() { CompressingXYDataset dataset = createDataset(XYDimension.X); double[] x = new double[] { .1, .2, .3, 1.1, 1.2 }; double[] y = new double[] { 2.1, 2.2, 2.3, 3.1, 3.2 }; for(int i = 0; i < x.length; i++) { dataset.add(x[i], y[i]); } DoubleData xData = dataset.getXData(); DoubleData yData = dataset.getYData(); assertEquals(4, xData.getLength()); assertEquals(4, yData.getLength()); assertEquals(0.0, xData.get(0)); assertEquals(2.1, yData.get(0)); assertEquals(0.0, xData.get(1)); assertEquals(2.3, yData.get(1)); assertEquals(1.0, xData.get(2)); assertEquals(3.1, yData.get(2)); assertEquals(1.0, xData.get(3)); assertEquals(3.2, yData.get(3)); assertEquals(.1, dataset.getMinX()); assertEquals(1.2, dataset.getMaxX()); assertEquals(2.1, dataset.getMinY()); assertEquals(3.2, dataset.getMaxY()); } public void testAddYIndependent() { CompressingXYDataset dataset = createDataset(XYDimension.Y); double[] y = new double[] { .1, .2, .3, 1.1, 1.2 }; double[] x = new double[] { 2.1, 2.2, 2.3, 3.1, 3.2 }; for(int i = 0; i < x.length; i++) { dataset.add(x[i], y[i]); } DoubleData xData = dataset.getXData(); DoubleData yData = dataset.getYData(); assertEquals(4, yData.getLength()); assertEquals(4, xData.getLength()); assertEquals(0.0, yData.get(0)); assertEquals(2.1, xData.get(0)); assertEquals(0.0, yData.get(1)); assertEquals(2.3, xData.get(1)); assertEquals(1.0, yData.get(2)); assertEquals(3.1, xData.get(2)); assertEquals(1.0, yData.get(3)); assertEquals(3.2, xData.get(3)); assertEquals(.1, dataset.getMinY()); assertEquals(1.2, dataset.getMaxY()); assertEquals(2.1, dataset.getMinX()); assertEquals(3.2, dataset.getMaxX()); } public void testMinMaxListeners() { final CompressingXYDataset dataset = createDataset(XYDimension.X); class TestListener implements MinMaxChangeListener { private final XYDimension dimension; int count; TestListener(XYDimension dimension) { this.dimension = dimension; } @Override public void minMaxChanged(CompressingXYDataset dataset2, XYDimension dimension) { assertSame(dataset, dataset2); assertEquals(this.dimension, dimension); count++; } } TestListener x = new TestListener(XYDimension.X); dataset.addXMinMaxChangeListener(x); TestListener y = new TestListener(XYDimension.Y); dataset.addYMinMaxChangeListener(y); dataset.add(0, 0); assertEquals(1, x.count); assertEquals(1, y.count); dataset.add(1, 1); assertEquals(2, x.count); assertEquals(2, y.count); dataset.add(2, 0.5); assertEquals(3, x.count); assertEquals(2, y.count); dataset.prepend(new double[] { -3, -2, -1 }, 0, new double[] { -1, 4, 5 }, 0, 3); assertEquals(4, x.count); assertEquals(3, y.count); dataset.prepend(new double[] { -6, -5, -4 }, 0, new double[] { 0, 0, 0 }, 0, 3); assertEquals(5, x.count); assertEquals(3, y.count); dataset.removeAllPoints(); assertEquals(6, x.count); assertEquals(4, y.count); } public void testTruncate() { CompressingXYDataset dataset = createDataset(XYDimension.X); dataset.add(0, 1); dataset.add(1, 2); dataset.add(2, 3); dataset.setTruncationPoint(1.5); dataset.setTruncationOffset(0); dataset.add(3, 4); dataset.add(4, 5); assertEquals(2.0, dataset.getMinX()); assertEquals(4.0, dataset.getMaxX()); assertEquals(3.0, dataset.getMinY()); assertEquals(5.0, dataset.getMaxY()); } public void testTruncateYIndependent() { CompressingXYDataset dataset = createDataset(XYDimension.Y); dataset.add(0, 1); dataset.add(1, 2); dataset.add(2, 3); dataset.setTruncationPoint(2.5); dataset.setTruncationOffset(0); dataset.add(3, 4); dataset.add(4, 5); assertEquals(2.0, dataset.getMinX()); assertEquals(4.0, dataset.getMaxX()); assertEquals(3.0, dataset.getMinY()); assertEquals(5.0, dataset.getMaxY()); } public void testTruncateWithOffset() { CompressingXYDataset dataset = createDataset(XYDimension.X); dataset.add(0, 1); dataset.add(1, 2); dataset.add(2, 3); dataset.setTruncationPoint(1.5); dataset.setTruncationOffset(1); dataset.add(3, 4); dataset.add(4, 5); assertEquals(1.0, dataset.getMinX()); assertEquals(4.0, dataset.getMaxX()); assertEquals(2.0, dataset.getMinY()); assertEquals(5.0, dataset.getMaxY()); } public void testTruncateWithOffsetYIndependent() { CompressingXYDataset dataset = createDataset(XYDimension.Y); dataset.add(0, 1); dataset.add(1, 2); dataset.add(2, 3); dataset.setTruncationPoint(2.5); dataset.setTruncationOffset(1); dataset.add(3, 4); dataset.add(4, 5); assertEquals(1.0, dataset.getMinX()); assertEquals(4.0, dataset.getMaxX()); assertEquals(2.0, dataset.getMinY()); assertEquals(5.0, dataset.getMaxY()); } public void testRemoveAll() { CompressingXYDataset dataset = createDataset(XYDimension.X); dataset.add(0, 0); dataset.add(1, 1); dataset.removeAllPoints(); assertEquals(0, dataset.getPointCount()); assertEquals(Double.POSITIVE_INFINITY, dataset.getMinX()); assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxX()); assertEquals(Double.POSITIVE_INFINITY, dataset.getMinY()); assertEquals(Double.NEGATIVE_INFINITY, dataset.getMaxY()); } public void testRecompress() { CompressingXYDataset dataset = createDataset(XYDimension.X); for(int i = 0; i < 10; i++) { dataset.add(i, i); } dataset.recompress(); assertEquals(10, dataset.getPointCount()); dataset.setCompressionScale(5); dataset.recompress(); assertEquals(4, dataset.getPointCount()); } public void testProperties() throws InvocationTargetException, IllegalAccessException, IntrospectionException { CompressingXYDataset dataset = createDataset(XYDimension.X); PropertyTester t = new PropertyTester(dataset); t.test("truncationPoint", -1.1, 0.0, 1.1); t.test("truncationOffset", 0, 1, 10); t.test("compressionScale", .1, 1.0, 10.0); t.test("compressionOffset", -10.0, 0.0, 10.0); } private CompressingXYDataset createDataset(XYDimension independentDimension) { XYAxis xAxis = new LinearXYAxis(XYDimension.X); XYAxis yAxis = new LinearXYAxis(XYDimension.Y); LinearXYPlotLine plotLine = new LinearXYPlotLine(xAxis, yAxis, independentDimension); XYPlotContents contents = new XYPlotContents(); contents.add(plotLine); CompressingXYDataset dataset = new CompressingXYDataset(plotLine, new DefaultCompressor()); dataset.setCompressionOffset(0); dataset.setCompressionScale(1); return dataset; } }
false
Plotter_src_test_java_plotter_xy_JUnitCompressingXYDataset.java
1,990
class TestListener implements MinMaxChangeListener { private final XYDimension dimension; int count; TestListener(XYDimension dimension) { this.dimension = dimension; } @Override public void minMaxChanged(CompressingXYDataset dataset2, XYDimension dimension) { assertSame(dataset, dataset2); assertEquals(this.dimension, dimension); count++; } }
false
Plotter_src_test_java_plotter_xy_JUnitCompressingXYDataset.java
1,991
public class JUnitDefaultCompressor extends TestCase { private PointData indata; private PointData expected; private DefaultCompressor compressor; private PointData outdata; @Override protected void setUp() throws Exception { super.setUp(); indata = new PointData(); expected = new PointData(); compressor = new DefaultCompressor(); outdata = new PointData(); } public void testCompress0() { check(); } public void testCompress1() { in(.5, 1); out(0, 1); check(); } public void testCompress1_NaN() { in(.5, Double.NaN); out(0, Double.NaN); check(); } public void testCompress2() { in(.5, 1); in(.6, 2); out(0, 1); out(0, 2); check(); } public void testCompress2_2() { in(.5, 2); in(.6, 1); out(0, 2); out(0, 1); check(); } public void testCompress2_NaN() { in(.5, 1); in(.6, Double.NaN); out(0, 1); out(0, Double.NaN); check(); } public void testCompress2_NaN2() { in(.5, Double.NaN); in(.6, 1); out(0, Double.NaN); out(0, 1); check(); } public void testCompress3() { in(.5, 1); in(.6, 2); in(.7, 3); out(0, 1); out(0, 3); check(); } public void testCompress3_2() { in(.5, 1); in(.6, 3); in(.7, 2); out(0, 1); out(0, 3); out(0, 2); check(); } public void testCompress3_3() { in(.5, 2); in(.6, 1); in(.7, 3); out(0, 2); out(0, 1); out(0, 3); check(); } public void testCompress3_4() { in(.5, 2); in(.6, 3); in(.7, 1); out(0, 2); out(0, 3); out(0, 1); check(); } public void testCompress3_5() { in(.5, 3); in(.6, 1); in(.7, 2); out(0, 3); out(0, 1); out(0, 2); check(); } public void testCompress3_6() { in(.5, 3); in(.6, 2); in(.7, 1); out(0, 3); out(0, 1); check(); } public void testCompress3_NaN() { in(.5, Double.NaN); in(.6, 2); in(.7, 3); out(0, Double.NaN); out(0, 2); out(0, 3); check(); } public void testCompress3_NaN2() { in(.5, 1); in(.6, Double.NaN); in(.7, 3); out(0, 1); out(0, Double.NaN); out(0, 3); check(); } public void testCompress3_NaN3() { in(.5, 1); in(.6, 2); in(.7, Double.NaN); out(0, 1); out(0, 2); out(0, Double.NaN); check(); } public void testCompress3_NaN4() { in(.5, Double.NaN); in(.6, 2); in(.7, Double.NaN); out(0, Double.NaN); out(0, 2); out(0, Double.NaN); check(); } public void testCompress() { in(.51, 3); in(.52, 4); in(.53, 5); in(.54, 6); in(.55, 7); in(.56, 1); in(.57, 2); out(0, 3); out(0, 1); out(0, 7); out(0, 2); check(); } public void testCompress_2() { in(.51, 1); in(.52, 2); in(.53, Double.NaN); in(.54, 3); in(.55, 4); out(0, 1); out(0, 2); out(0, Double.NaN); out(0, 3); out(0, 4); check(); } public void testCompress_3() { in(.51, 2); in(.52, 1); in(.53, Double.NaN); in(.54, 4); in(.55, 3); out(0, 2); out(0, 1); out(0, Double.NaN); out(0, 4); out(0, 3); check(); } public void testCompress_4() { in(.51, 4); in(.52, 3); in(.53, Double.NaN); in(.54, 2); in(.55, 1); out(0, 4); out(0, 3); out(0, Double.NaN); out(0, 2); out(0, 1); check(); } public void testCompress_5() { in(.51, 3); in(.52, 4); in(.53, Double.NaN); in(.54, 1); in(.55, 2); out(0, 3); out(0, 4); out(0, Double.NaN); out(0, 1); out(0, 2); check(); } public void testCompress_6() { in(1.2, -10); in(1.4, -5); in(1.6, Double.NaN); in(1.8, 5); out(1, -10); out(1, -5); out(1, Double.NaN); out(1, 5); check(); } public void testCompress_7() { in(1.2, -10); in(1.4, Double.NaN); in(1.6, -5); in(1.8, 5); out(1, -10); out(1, Double.NaN); out(1, -5); out(1, 5); check(); } public void testCompress_8() { in(1.2, -10); in(1.25, -9); in(1.3, Double.NaN); in(1.35, -7); in(1.4, -5); in(1.6, Double.NaN); in(1.8, 5); out(1, -10); out(1, -9); out(1, Double.NaN); out(1, -7); out(1, -5); out(1, Double.NaN); out(1, 5); check(); } public void testCompress_9() { in(1.1, -10); in(1.2, Double.NaN); in(1.3, -7); in(1.4, -5); in(1.5, Double.NaN); in(1.6, -2); in(1.7, 5); out(1, -10); out(1, Double.NaN); out(1, -7); out(1, -5); out(1, Double.NaN); out(1, -2); out(1, 5); check(); } public void testCompress10() { in(.3, Double.NaN); in(.4, 1); in(.5, Double.NaN); in(.6, 2); in(.7, Double.NaN); in(.8, 5); in(.9, Double.NaN); out(0, Double.NaN); out(0, 1); out(0, Double.NaN); out(0, 2); out(0, Double.NaN); out(0, 5); out(0, Double.NaN); check(); } public void testCompress11() { in(0, 5); in(.2, Double.NaN); in(.3, -10); in(.4, -5); in(.5, Double.NaN); in(.7, 10); out(0, 5); out(0, Double.NaN); out(0, -10); out(0, -5); out(0, Double.NaN); out(0, 10); check(); } public void testCompress12() { in(0.5, 5); in(1, 5); in(1.1, Double.NaN); in(1.2, -5); out(0, 5); out(1, 5); out(1, Double.NaN); out(1, -5); check(); } public void testMultiBucket() { in(.5, 1); in(1.5, 2); out(0, 1); out(1, 2); check(); } public void testMultiBucket2() { in(.5, 1); in(2.5, 2); in(4.5, 3); out(0, 1); out(2, 2); out(4, 3); check(); } public void testMultiBucket3() { in(.5, 1); in(2.5, 2); in(2.6, 2.3); in(2.7, 2.5); in(4.5, 3); out(0, 1); out(2, 2); out(2, 2.5); out(4, 3); check(); } public void testMultiBucket4() { in(.5, 1); in(1.4, Double.NaN); in(1.5, 2); out(0, 1); out(1, Double.NaN); out(1, 2); check(); } public void testStreaming() { StreamingCompressor s = compressor.createStreamingCompressor(outdata, 0, 1); assertEquals(1, s.add(0, 1)); expected.add(0, 1); checkNoCompress(); assertEquals(2, s.add(.1, 2)); expected.add(0, 2); checkNoCompress(); assertEquals(2, s.add(.2, 3)); expected.removeLast(2); expected.add(0, 1); expected.add(0, 3); checkNoCompress(); assertEquals(3, s.add(.3, 2)); expected.add(0, 2); checkNoCompress(); assertEquals(3, s.add(.4, 2.5)); expected.removeLast(1); expected.add(0, 2.5); checkNoCompress(); assertEquals(4, s.add(1, 5)); expected.add(1, 5); checkNoCompress(); assertEquals(2, s.add(1, 6)); expected.add(1, 6); checkNoCompress(); } public void testFlatLine() { in(.51, 3); in(.52, 3); in(.53, 3); in(.54, 3); in(.55, 3); in(.56, 3); in(.57, 3); out(0, 3); check(); } public void testFlatLineNaN() { in(.51, Double.NaN); in(.52, Double.NaN); in(.53, Double.NaN); in(.54, Double.NaN); in(.55, Double.NaN); in(.56, Double.NaN); in(.57, Double.NaN); out(0, Double.NaN); check(); } private void in(double x, double y) { indata.add(x, y); } private void out(double x, double y) { expected.add(x, y); } private void check() { compressor.compress(indata, outdata, 0, 1); checkNoCompress(); } private void checkNoCompress() { StringBuffer b = new StringBuffer(); b.append("input = "); appendPoints(b, indata); b.append(", expected = "); appendPoints(b, expected); b.append(", actual = "); appendPoints(b, outdata); String msg = b.toString(); DoubleData outx = outdata.getX(); DoubleData outy = outdata.getY(); DoubleData expectedx = expected.getX(); DoubleData expectedy = expected.getY(); int n = expectedx.getLength(); assertEquals(msg, n, outx.getLength()); for(int i = 0; i < n; i++) { assertEquals(msg + ", i = " + i, expectedx.get(i), outx.get(i)); assertEquals(msg + ", i = " + i, expectedy.get(i), outy.get(i)); } } private void appendPoints(StringBuffer b, PointData data) { b.append("["); DoubleData x = data.getX(); DoubleData y = data.getY(); int n = x.getLength(); for(int i = 0; i < n; i++) { b.append("("); b.append(x.get(i)); b.append(","); b.append(y.get(i)); b.append(")"); if(i < n - 1) { b.append(","); } } b.append("]"); } }
false
Plotter_src_test_java_plotter_xy_JUnitDefaultCompressor.java
1,992
public class JUnitDefaultXYLayoutGenerator extends TestCase { public void testBasic() { XYPlot plot = new XYPlot(); XYPlotContents contents = new XYPlotContents(); plot.add(contents); new DefaultXYLayoutGenerator().generateLayout(plot); plot.setSize(100, 100); plot.doLayout(); assertEquals(0, contents.getX()); assertEquals(0, contents.getY()); assertEquals(100, contents.getWidth()); assertEquals(100, contents.getHeight()); } public void testNormal() { XYPlot plot = new XYPlot(); XYPlotContents contents = new XYPlotContents(); plot.add(contents); LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X); plot.add(xAxis); xAxis.setPreferredSize(new Dimension(1, 10)); LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y); plot.add(yAxis); yAxis.setPreferredSize(new Dimension(10, 1)); new DefaultXYLayoutGenerator().generateLayout(plot); plot.setSize(100, 100); plot.doLayout(); assertEquals(10, contents.getX()); assertEquals(0, contents.getY()); assertEquals(90, contents.getWidth()); assertEquals(90, contents.getHeight()); assertEquals(0, xAxis.getX()); assertEquals(90, xAxis.getY()); assertEquals(100, xAxis.getWidth()); assertEquals(10, xAxis.getHeight()); assertEquals(0, yAxis.getX()); assertEquals(0, yAxis.getY()); assertEquals(10, yAxis.getWidth()); assertEquals(100, yAxis.getHeight()); } public void testFull() { XYPlot plot = new XYPlot(); XYPlotContents contents = new XYPlotContents(); plot.add(contents); LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X); plot.add(xAxis); xAxis.setPreferredSize(new Dimension(1, 10)); LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y); plot.add(yAxis); yAxis.setPreferredSize(new Dimension(10, 1)); SlopeLineDisplay slopeDisplay = new SlopeLineDisplay(); plot.add(slopeDisplay); slopeDisplay.setPreferredSize(new Dimension(1, 10)); XYLocationDisplay locationDisplay = new XYLocationDisplay(); plot.add(locationDisplay); locationDisplay.setPreferredSize(new Dimension(1, 10)); new DefaultXYLayoutGenerator().generateLayout(plot); plot.setSize(100, 100); plot.doLayout(); assertEquals(10, contents.getX()); assertEquals(10, contents.getY()); assertEquals(90, contents.getWidth()); assertEquals(80, contents.getHeight()); assertEquals(0, xAxis.getX()); assertEquals(90, xAxis.getY()); assertEquals(100, xAxis.getWidth()); assertEquals(10, xAxis.getHeight()); assertEquals(0, yAxis.getX()); assertEquals(0, yAxis.getY()); assertEquals(10, yAxis.getWidth()); assertEquals(100, yAxis.getHeight()); assertEquals(10, locationDisplay.getX()); assertEquals(0, locationDisplay.getY()); assertEquals(45, locationDisplay.getWidth()); assertEquals(10, locationDisplay.getHeight()); assertEquals(55, slopeDisplay.getX()); assertEquals(0, slopeDisplay.getY()); assertEquals(45, slopeDisplay.getWidth()); assertEquals(10, slopeDisplay.getHeight()); } public void testSlopeDisplayNoLocation() { XYPlot plot = new XYPlot(); XYPlotContents contents = new XYPlotContents(); plot.add(contents); LinearXYAxis xAxis = new LinearXYAxis(XYDimension.X); plot.add(xAxis); xAxis.setPreferredSize(new Dimension(1, 10)); LinearXYAxis yAxis = new LinearXYAxis(XYDimension.Y); plot.add(yAxis); yAxis.setPreferredSize(new Dimension(10, 1)); SlopeLineDisplay slopeDisplay = new SlopeLineDisplay(); plot.add(slopeDisplay); slopeDisplay.setPreferredSize(new Dimension(1, 10)); new DefaultXYLayoutGenerator().generateLayout(plot); plot.setSize(100, 100); plot.doLayout(); assertEquals(10, contents.getX()); assertEquals(10, contents.getY()); assertEquals(90, contents.getWidth()); assertEquals(80, contents.getHeight()); assertEquals(0, xAxis.getX()); assertEquals(90, xAxis.getY()); assertEquals(100, xAxis.getWidth()); assertEquals(10, xAxis.getHeight()); assertEquals(0, yAxis.getX()); assertEquals(0, yAxis.getY()); assertEquals(10, yAxis.getWidth()); assertEquals(100, yAxis.getHeight()); assertEquals(55, slopeDisplay.getX()); assertEquals(0, slopeDisplay.getY()); assertEquals(45, slopeDisplay.getWidth()); assertEquals(10, slopeDisplay.getHeight()); } }
false
Plotter_src_test_java_plotter_xy_JUnitDefaultXYLayoutGenerator.java
1,993
public class JUnitLinearXYAxis extends TestCase { public void testToLogicalX() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(1); axis.setEnd(2); DoubleDiffer d = new DoubleDiffer(.0000001); d.assertClose(1, axis.toLogical(-1)); d.assertClose(1.5, axis.toLogical(49)); d.assertClose(2, axis.toLogical(99)); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); d.assertClose(1, axis.toLogical(9)); d.assertClose(1.5, axis.toLogical(59)); d.assertClose(2, axis.toLogical(109)); } public void testToLogicalXInverted() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(2); axis.setEnd(1); DoubleDiffer d = new DoubleDiffer(.0000001); d.assertClose(2, axis.toLogical(-1)); d.assertClose(1.5, axis.toLogical(49)); d.assertClose(1, axis.toLogical(99)); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); d.assertClose(2, axis.toLogical(9)); d.assertClose(1.5, axis.toLogical(59)); d.assertClose(1, axis.toLogical(109)); } public void testToLogicalY() { DoubleDiffer d = new DoubleDiffer(.0000001); LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(1); axis.setEnd(2); d.assertClose(2, axis.toLogical(0)); d.assertClose(1.5, axis.toLogical(50)); d.assertClose(1, axis.toLogical(100)); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); d.assertClose(2, axis.toLogical(20)); d.assertClose(1.5, axis.toLogical(70)); d.assertClose(1, axis.toLogical(120)); } public void testToLogicalYInverted() { DoubleDiffer d = new DoubleDiffer(.0000001); LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(2); axis.setEnd(1); d.assertClose(1, axis.toLogical(0)); d.assertClose(1.5, axis.toLogical(50)); d.assertClose(2, axis.toLogical(100)); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); d.assertClose(1, axis.toLogical(20)); d.assertClose(1.5, axis.toLogical(70)); d.assertClose(2, axis.toLogical(120)); } public void testToPhysicalX() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(1); axis.setEnd(2); assertEquals(-1, axis.toPhysical(1)); assertEquals(49, axis.toPhysical(1.5)); assertEquals(99, axis.toPhysical(2)); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); assertEquals(9, axis.toPhysical(1)); assertEquals(59, axis.toPhysical(1.5)); assertEquals(109, axis.toPhysical(2)); } public void testToPhysicalXInverted() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(2); axis.setEnd(1); assertEquals(99, axis.toPhysical(1)); assertEquals(49, axis.toPhysical(1.5)); assertEquals(-1, axis.toPhysical(2)); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); assertEquals(109, axis.toPhysical(1)); assertEquals(59, axis.toPhysical(1.5)); assertEquals(9, axis.toPhysical(2)); } public void testToPhysicalY() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(1); axis.setEnd(2); assertEquals(100, axis.toPhysical(1)); assertEquals(50, axis.toPhysical(1.5)); assertEquals(0, axis.toPhysical(2)); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); assertEquals(120, axis.toPhysical(1)); assertEquals(70, axis.toPhysical(1.5)); assertEquals(20, axis.toPhysical(2)); } public void testToPhysicalYInverted() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(2); axis.setEnd(1); assertEquals(0, axis.toPhysical(1)); assertEquals(50, axis.toPhysical(1.5)); assertEquals(100, axis.toPhysical(2)); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); assertEquals(20, axis.toPhysical(1)); assertEquals(70, axis.toPhysical(1.5)); assertEquals(120, axis.toPhysical(2)); } public void testTickMarksX() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(1); axis.setEnd(2); axis.doLayout(); int[] majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(-1, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(99, majorTicks[2]); Component[] components = axis.getComponents(); assertEquals(Arrays.toString(components), 3, components.length); assertEquals("1", ((JLabel) components[0]).getText()); assertEquals("1.5", ((JLabel) components[1]).getText()); assertEquals("2", ((JLabel) components[2]).getText()); int[] minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(-1, minorTicks[0]); assertEquals(9, minorTicks[1]); assertEquals(19, minorTicks[2]); assertEquals(29, minorTicks[3]); assertEquals(39, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(59, minorTicks[6]); assertEquals(69, minorTicks[7]); assertEquals(79, minorTicks[8]); assertEquals(89, minorTicks[9]); assertEquals(99, minorTicks[10]); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); axis.doLayout(); majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(-1, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(99, majorTicks[2]); minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(-1, minorTicks[0]); assertEquals(9, minorTicks[1]); assertEquals(19, minorTicks[2]); assertEquals(29, minorTicks[3]); assertEquals(39, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(59, minorTicks[6]); assertEquals(69, minorTicks[7]); assertEquals(79, minorTicks[8]); assertEquals(89, minorTicks[9]); assertEquals(99, minorTicks[10]); } public void testTickMarksXInverted() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setSize(100, 10); axis.setStart(2); axis.setEnd(1); axis.doLayout(); int[] majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(99, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(-1, majorTicks[2]); Component[] components = axis.getComponents(); assertEquals(Arrays.toString(components), 3, components.length); assertEquals("1", ((JLabel) components[0]).getText()); assertEquals("1.5", ((JLabel) components[1]).getText()); assertEquals("2", ((JLabel) components[2]).getText()); int[] minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(99, minorTicks[0]); assertEquals(89, minorTicks[1]); assertEquals(79, minorTicks[2]); assertEquals(69, minorTicks[3]); assertEquals(59, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(39, minorTicks[6]); assertEquals(29, minorTicks[7]); assertEquals(19, minorTicks[8]); assertEquals(9, minorTicks[9]); assertEquals(-1, minorTicks[10]); axis.setSize(130, 10); axis.setStartMargin(10); axis.setEndMargin(20); axis.doLayout(); majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(99, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(-1, majorTicks[2]); minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(99, minorTicks[0]); assertEquals(89, minorTicks[1]); assertEquals(79, minorTicks[2]); assertEquals(69, minorTicks[3]); assertEquals(59, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(39, minorTicks[6]); assertEquals(29, minorTicks[7]); assertEquals(19, minorTicks[8]); assertEquals(9, minorTicks[9]); assertEquals(-1, minorTicks[10]); } public void testTickMarksY() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(1); axis.setEnd(2); axis.doLayout(); int[] majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(-1, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(99, majorTicks[2]); Component[] components = axis.getComponents(); assertEquals(Arrays.toString(components), 3, components.length); assertEquals("1", ((JLabel) components[0]).getText()); assertEquals("1.5", ((JLabel) components[1]).getText()); assertEquals("2", ((JLabel) components[2]).getText()); int[] minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(-1, minorTicks[0]); assertEquals(9, minorTicks[1]); assertEquals(19, minorTicks[2]); assertEquals(29, minorTicks[3]); assertEquals(39, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(59, minorTicks[6]); assertEquals(69, minorTicks[7]); assertEquals(79, minorTicks[8]); assertEquals(89, minorTicks[9]); assertEquals(99, minorTicks[10]); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); axis.doLayout(); majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(-1, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(99, majorTicks[2]); minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(-1, minorTicks[0]); assertEquals(9, minorTicks[1]); assertEquals(19, minorTicks[2]); assertEquals(29, minorTicks[3]); assertEquals(39, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(59, minorTicks[6]); assertEquals(69, minorTicks[7]); assertEquals(79, minorTicks[8]); assertEquals(89, minorTicks[9]); assertEquals(99, minorTicks[10]); } public void testTickMarksYInverted() { LinearXYAxis axis = new LinearXYAxis(XYDimension.Y); axis.setSize(10, 100); axis.setStart(2); axis.setEnd(1); axis.doLayout(); int[] majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(99, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(-1, majorTicks[2]); Component[] components = axis.getComponents(); assertEquals(Arrays.toString(components), 3, components.length); assertEquals("1", ((JLabel) components[0]).getText()); assertEquals("1.5", ((JLabel) components[1]).getText()); assertEquals("2", ((JLabel) components[2]).getText()); int[] minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(99, minorTicks[0]); assertEquals(89, minorTicks[1]); assertEquals(79, minorTicks[2]); assertEquals(69, minorTicks[3]); assertEquals(59, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(39, minorTicks[6]); assertEquals(29, minorTicks[7]); assertEquals(19, minorTicks[8]); assertEquals(9, minorTicks[9]); assertEquals(-1, minorTicks[10]); axis.setSize(10, 130); axis.setStartMargin(10); axis.setEndMargin(20); axis.doLayout(); majorTicks = axis.getMajorTicks(); assertEquals(Arrays.toString(majorTicks), 3, majorTicks.length); assertEquals(99, majorTicks[0]); assertEquals(49, majorTicks[1]); assertEquals(-1, majorTicks[2]); minorTicks = axis.getMinorTicks(); assertEquals(11, minorTicks.length); assertEquals(99, minorTicks[0]); assertEquals(89, minorTicks[1]); assertEquals(79, minorTicks[2]); assertEquals(69, minorTicks[3]); assertEquals(59, minorTicks[4]); assertEquals(49, minorTicks[5]); assertEquals(39, minorTicks[6]); assertEquals(29, minorTicks[7]); assertEquals(19, minorTicks[8]); assertEquals(9, minorTicks[9]); assertEquals(-1, minorTicks[10]); } public void testShift() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); axis.setStart(1); axis.setEnd(2); axis.shift(5); assertEquals(6.0, axis.getStart()); assertEquals(7.0, axis.getEnd()); } public void testSetFont() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); JLabel label = new JLabel(); axis.add(label); Font font = new Font("Helvetica", Font.ITALIC, 72); axis.setFont(font); assertSame(font, axis.getFont()); assertSame(font, label.getFont()); } public void testSetForeground() { LinearXYAxis axis = new LinearXYAxis(XYDimension.X); JLabel label = new JLabel(); axis.add(label); Color foreground = Color.cyan; axis.setForeground(foreground); assertSame(foreground, axis.getForeground()); assertSame(foreground, label.getForeground()); } public void testProperties() throws InvocationTargetException, IllegalAccessException, IntrospectionException { PropertyTester p = new PropertyTester(new LinearXYAxis(XYDimension.X)); p.test("textMargin", 0, 1); p.test("showLabels", true, false); p.test("minorTickLength", 0, 1); p.test("majorTickLength", 0, 1); p.test("tickMarkCalculator", new IntegerTickMarkCalculator()); p.test("format", new DecimalFormat("0.00")); } }
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYAxis.java
1,994
public class JUnitLinearXYPlotLine extends TestCase { private LinearXYPlotLine line; private XYPlot plot; private List<Rectangle> repaints = new ArrayList<Rectangle>(); @Override protected void setUp() throws Exception { XYAxis xAxis = new LinearXYAxis(XYDimension.X); XYAxis yAxis = new LinearXYAxis(XYDimension.Y); xAxis.setStart(0); xAxis.setEnd(1); yAxis.setStart(0); yAxis.setEnd(1); line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X) { private static final long serialVersionUID = 1L; @Override public void repaint(int x, int y, int width, int height) { repaints.add(new Rectangle(x, y, width, height)); super.repaint(x, y, width, height); } }; XYPlotContents contents = new XYPlotContents(); contents.add(line); plot = new XYPlot(); plot.add(contents); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); new DefaultXYLayoutGenerator().generateLayout(plot); } private void add(double x, double y) { line.getXData().add(x); line.getYData().add(y); } public void testPaintSimple() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintInverted() throws InterruptedException, InvocationTargetException { plot.getXAxis().setStart(1); plot.getXAxis().setEnd(0); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(179, 180, 19, 20); c.check(g.getLines()); } public void testPaintLeadingNaN() throws InterruptedException, InvocationTargetException { add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaN() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaN() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(4, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintTrailingTripleNaN() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.9, .9); add(.95, Double.NaN); add(.96, Double.NaN); add(.97, Double.NaN); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintSimpleStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintLeadingNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 160); c.require(19, 160, 39, 160); c.require(159, 40, 159, 20); c.require(159, 20, 179, 20); c.check(g.getLines()); } public void testPaintSimpleStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintLeadingNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 180); c.require(39, 180, 39, 160); c.require(159, 40, 179, 40); c.require(179, 40, 179, 20); c.check(g.getLines()); } public void testPaintClip() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.5, .5); add(.9, .9); CountingGraphics g = paint(new Rectangle(150, 0, 50, 200)); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(99, 100, 179, 20); c.check(g.getLines()); } public void testPaintClipInverted() throws InterruptedException, InvocationTargetException { plot.getXAxis().setStart(1); plot.getXAxis().setEnd(0); add(.1, .1); add(.5, .5); add(.9, .9); CountingGraphics g = paint(new Rectangle(0, 0, 50, 200)); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(99, 100, 19, 20); c.check(g.getLines()); } public void testPaintMissingPointLeft() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.LEFT); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(5, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 99, 160); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointRight() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.RIGHT); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(5, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(99, 40, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointBoth() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.BOTH); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 99, 160); c.require(99, 40, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointLeftWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.LEFT); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 99, 160); c.require(159, 40, 179, 20); c.require(179, 20, 199, 20); c.check(g.getLines()); } public void testPaintMissingPointRightWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.RIGHT); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(-1, 180, 19, 180); c.require(19, 180, 39, 160); c.require(99, 40, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointBothWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.BOTH); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(8, g.getPointCount()); LineChecker c = new LineChecker(); c.require(-1, 180, 19, 180); c.require(19, 180, 39, 160); c.require(39, 160, 99, 160); c.require(99, 40, 159, 40); c.require(159, 40, 179, 20); c.require(179, 20, 199, 20); c.check(g.getLines()); } public void testRepaint() { add(.1, .2); add(.2, .3); add(.3, .4); line.setSize(200, 200); plot.getXAxis().setSize(200, 1); plot.getYAxis().setSize(1, 200); repaints.clear(); line.repaintData(1); assertEquals(1, repaints.size()); assertEquals(new Rectangle(18, 119, 42, 42), repaints.get(0)); } public void testRepaintInverted() { add(.1, .2); add(.2, .3); add(.3, .4); line.setSize(200, 200); plot.getXAxis().setStart(1); plot.getXAxis().setEnd(0); plot.getXAxis().setSize(200, 1); plot.getYAxis().setSize(1, 200); repaints.clear(); line.repaintData(1); assertEquals(1, repaints.size()); assertEquals(new Rectangle(138, 119, 42, 42), repaints.get(0)); } public void testPointOutline() throws InterruptedException, InvocationTargetException { line.setPointOutline(createSquare()); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(12, g.getPointCount()); assertEquals(2, g.getShapeCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); // Point 1 c.require(14, 175, 14, 185); c.require(14, 185, 24, 185); c.require(24, 185, 24, 175); c.require(24, 175, 14, 175); // Point 2 c.require(174, 15, 174, 25); c.require(174, 25, 184, 25); c.require(184, 25, 184, 15); c.require(184, 15, 174, 15); c.check(g.getLines()); } public void testPointOutlineNaN() throws InterruptedException, InvocationTargetException { line.setPointOutline(createSquare()); add(.1, .1); add(.5, Double.NaN); add(.9, .9); CountingGraphics g = paint(); assertEquals(10, g.getPointCount()); assertEquals(2, g.getShapeCount()); LineChecker c = new LineChecker(); // Point 1 c.require(14, 175, 14, 185); c.require(14, 185, 24, 185); c.require(24, 185, 24, 175); c.require(24, 175, 14, 175); // Point 3 c.require(174, 15, 174, 25); c.require(174, 25, 184, 25); c.require(184, 25, 184, 15); c.require(184, 15, 174, 15); c.check(g.getLines()); } private GeneralPath createSquare() { GeneralPath pointShape = new GeneralPath(); pointShape.moveTo(-5, -5); pointShape.lineTo(-5, 5); pointShape.lineTo(5, 5); pointShape.lineTo(5, -5); pointShape.lineTo(-5, -5); return pointShape; } private CountingGraphics paint() throws InterruptedException, InvocationTargetException { return paint(null); } // Ensures that the line is 200x200, paints it, and returns the stats. // We can't use 100x100 because on Mac OSX, the minimum frame width is 128. private CountingGraphics paint(Shape clip) throws InterruptedException, InvocationTargetException { final JFrame frame = new JFrame(); frame.getContentPane().add(plot); BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR); final Graphics2D imageG = image.createGraphics(); final CountingGraphics g = new CountingGraphics(imageG); try { if(clip != null) { g.setClip(clip); } SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { frame.pack(); int xo = 200 - line.getWidth(); int yo = 200 - line.getHeight(); frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo); frame.validate(); // These are sanity checks to make sure our setup is correct, not actual functionality tests. assertEquals(200, line.getWidth()); assertEquals(200, line.getHeight()); line.paint(g); } finally { frame.dispose(); } } }); } finally { imageG.dispose(); } return g; } }
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLine.java
1,995
line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X) { private static final long serialVersionUID = 1L; @Override public void repaint(int x, int y, int width, int height) { repaints.add(new Rectangle(x, y, width, height)); super.repaint(x, y, width, height); } };
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLine.java
1,996
SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { frame.pack(); int xo = 200 - line.getWidth(); int yo = 200 - line.getHeight(); frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo); frame.validate(); // These are sanity checks to make sure our setup is correct, not actual functionality tests. assertEquals(200, line.getWidth()); assertEquals(200, line.getHeight()); line.paint(g); } finally { frame.dispose(); } } });
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLine.java
1,997
public class JUnitLinearXYPlotLineYIndependent extends TestCase { private LinearXYPlotLine line; private XYPlot plot; private List<Rectangle> repaints = new ArrayList<Rectangle>(); @Override protected void setUp() throws Exception { XYAxis xAxis = new LinearXYAxis(XYDimension.X); XYAxis yAxis = new LinearXYAxis(XYDimension.Y); xAxis.setStart(0); xAxis.setEnd(1); yAxis.setStart(0); yAxis.setEnd(1); line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.Y) { private static final long serialVersionUID = 1L; @Override public void repaint(int x, int y, int width, int height) { repaints.add(new Rectangle(x, y, width, height)); super.repaint(x, y, width, height); } }; XYPlotContents contents = new XYPlotContents(); contents.add(line); plot = new XYPlot(); plot.add(contents); plot.add(xAxis); plot.add(yAxis); plot.setXAxis(xAxis); plot.setYAxis(yAxis); new DefaultXYLayoutGenerator().generateLayout(plot); } private void add(double x, double y) { line.getXData().add(y); line.getYData().add(x); } public void testPaintSimple() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintInverted() throws InterruptedException, InvocationTargetException { plot.getYAxis().setStart(1); plot.getYAxis().setEnd(0); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(179, 180, 19, 20); c.check(g.getLines()); } public void testPaintLeadingNaN() throws InterruptedException, InvocationTargetException { add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaN() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaN() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(4, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintSimpleStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintLeadingNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 20); c.require(19, 20, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaNStep() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_YX); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 19, 160); c.require(19, 160, 39, 160); c.require(159, 40, 159, 20); c.require(159, 20, 179, 20); c.check(g.getLines()); } public void testPaintSimpleStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintLeadingNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.05, Double.NaN); add(.1, .1); add(.9, .9); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintTrailingNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.9, .9); add(.95, Double.NaN); CountingGraphics g = paint(); assertEquals(3, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 179, 180); c.require(179, 180, 179, 20); c.check(g.getLines()); } public void testPaintMiddleNaNStepXY() throws InterruptedException, InvocationTargetException { line.setLineMode(LineMode.STEP_XY); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 180); c.require(39, 180, 39, 160); c.require(159, 40, 179, 40); c.require(179, 40, 179, 20); c.check(g.getLines()); } public void testPaintClip() throws InterruptedException, InvocationTargetException { add(.1, .1); add(.5, .5); add(.9, .9); CountingGraphics g = paint(new Rectangle(0, 0, 200, 50)); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(99, 100, 179, 20); c.check(g.getLines()); } public void testPaintClipInverted() throws InterruptedException, InvocationTargetException { plot.getYAxis().setStart(1); plot.getYAxis().setEnd(0); add(.1, .1); add(.5, .5); add(.9, .9); CountingGraphics g = paint(new Rectangle(0, 150, 200, 50)); assertEquals(2, g.getPointCount()); LineChecker c = new LineChecker(); c.require(99, 100, 179, 180); c.check(g.getLines()); } public void testPaintMissingPointLeft() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.LEFT); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(5, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 39, 100); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointRight() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.RIGHT); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(5, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(159, 100, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointBoth() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.BOTH); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 39, 100); c.require(159, 100, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointLeftWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.LEFT); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 180, 39, 160); c.require(39, 160, 39, 100); c.require(159, 40, 179, 20); c.require(179, 20, 179, 0); c.check(g.getLines()); } public void testPaintMissingPointRightWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.RIGHT); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(6, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 200, 19, 180); c.require(19, 180, 39, 160); c.require(159, 100, 159, 40); c.require(159, 40, 179, 20); c.check(g.getLines()); } public void testPaintMissingPointBothWithMissingEnds() throws InterruptedException, InvocationTargetException { line.setMissingPointMode(MissingPointMode.BOTH); add(0, Double.NaN); add(.1, .1); add(.2, .2); add(.5, Double.NaN); add(.8, .8); add(.9, .9); add(1, Double.NaN); CountingGraphics g = paint(); assertEquals(8, g.getPointCount()); LineChecker c = new LineChecker(); c.require(19, 200, 19, 180); c.require(19, 180, 39, 160); c.require(39, 160, 39, 100); c.require(159, 100, 159, 40); c.require(159, 40, 179, 20); c.require(179, 20, 179, 0); c.check(g.getLines()); } public void testRepaint() { add(.1, .2); add(.2, .3); add(.3, .4); line.setSize(200, 200); plot.getXAxis().setSize(200, 1); plot.getYAxis().setSize(1, 200); repaints.clear(); line.repaintData(1); assertEquals(1, repaints.size()); assertEquals(new Rectangle(38, 139, 42, 42), repaints.get(0)); } public void testRepaintInverted() { add(.1, .2); add(.2, .3); add(.3, .4); line.setSize(200, 200); plot.getYAxis().setStart(1); plot.getYAxis().setEnd(0); plot.getXAxis().setSize(200, 1); plot.getYAxis().setSize(1, 200); repaints.clear(); line.repaintData(1); assertEquals(1, repaints.size()); assertEquals(new Rectangle(38, 19, 42, 42), repaints.get(0)); } private CountingGraphics paint() throws InterruptedException, InvocationTargetException { return paint(null); } // Ensures that the line is 200x200, paints it, and returns the stats. // We can't use 100x100 because on Mac OSX, the minimum frame width is 128. private CountingGraphics paint(Shape clip) throws InterruptedException, InvocationTargetException { final JFrame frame = new JFrame(); frame.getContentPane().add(plot); BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_3BYTE_BGR); final Graphics2D imageG = image.createGraphics(); final CountingGraphics g = new CountingGraphics(imageG); try { if(clip != null) { g.setClip(clip); } SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { frame.pack(); int xo = 200 - line.getWidth(); int yo = 200 - line.getHeight(); frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo); frame.validate(); // These are sanity checks to make sure our setup is correct, not actual functionality tests. assertEquals(200, line.getWidth()); assertEquals(200, line.getHeight()); line.paint(g); } finally { frame.dispose(); } } }); } finally { imageG.dispose(); } return g; } }
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLineYIndependent.java
1,998
line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.Y) { private static final long serialVersionUID = 1L; @Override public void repaint(int x, int y, int width, int height) { repaints.add(new Rectangle(x, y, width, height)); super.repaint(x, y, width, height); } };
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLineYIndependent.java
1,999
SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { frame.pack(); int xo = 200 - line.getWidth(); int yo = 200 - line.getHeight(); frame.setSize(frame.getWidth() + xo, frame.getHeight() + yo); frame.validate(); // These are sanity checks to make sure our setup is correct, not actual functionality tests. assertEquals(200, line.getWidth()); assertEquals(200, line.getHeight()); line.paint(g); } finally { frame.dispose(); } } });
false
Plotter_src_test_java_plotter_xy_JUnitLinearXYPlotLineYIndependent.java