📄 paralleldisplay.java
字号:
/*Copyright (c) 2001, 2002, 2003 Flo Ledermann <flo@subnet.at>This file is part of parvis - a parallel coordiante based data visualisationtool written in java. You find parvis and additional information on itswebsite at http://www.mediavirus.org/parvis.parvis is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.parvis is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with parvis (in the file LICENSE.txt); if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/package org.mediavirus.parvis.gui;import org.mediavirus.parvis.model.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.util.*;/** * The swing GUI Component for displaying a parallel coordinate visualisation. * Note that the actual rendering is done by the UI delegate, ParallelDisplayUI * (with its single subclass BasiParallelDisplayUI). This class is used to store * the state of the component and interact with the environment. * * @author Flo Ledermann flo@subnet.at * @version 0.1 */public class ParallelDisplay extends JComponent implements ChangeListener { /** Scale values for the axes.*/ //private float axisScale[] = null; /** Offset values for the axes.*/ //private float axisOffset[] = null; /** axis -> dimension linking. */ //protected int axisOrder[] = null; protected Axis axes[]; /** Helper class for string the properties of an axis. */ class Axis { int dimension; float scale; float offset; String label; Axis(int dimension, float scale, float offset, String label){ this.dimension = dimension; this.scale = scale; this.offset = offset; this.label = label; } } /** brushed values of records */ protected float brushValues[] = null; /** Our model. */ private ParallelSpaceModel model; /** The mode of interaction we are in.*/ protected int editMode = 0; public static final int REORDER = 0; public static final int SCALE = 1; public static final int TRANSLATE = 2; /** used to invert axis orientation */ public static final int INVERT = 3; public static final int BRUSH = 4; public static final int HISTO_TOTALREC = 0; public static final int HISTO_BINREC = 1; public static final int HISTO_BRUSHREC = 2; /** Whether we have to redraw the whole background. This is usually only * needed if the model changes. */ public boolean deepRepaint = true; boolean brushChanged = false; ParallelPopup popupMenu; static { UIManager.put("org.mediavirus.parvis.gui.ParallelDisplayUI", "org.mediavirus.parvis.gui.BasicParallelDisplayUI"); } /** * Creates a new ParallelDisplay. */ public ParallelDisplay() { init(null); } /** * Creates a new ParallelDisplay with the given model. * * @param model The model to display. */ public ParallelDisplay(ParallelSpaceModel model){ init(model); } /** * Initializes the component with the given model. * * @param model The model to use. */ protected void init(ParallelSpaceModel model){ System.out.println("Initializing ParallelDisplay Component"); popupMenu = new ParallelPopup(this); setModel(model); setMinimumSize(new Dimension(100, 100)); setPreferredSize(new Dimension(700,400)); setBackground(Color.white); setDoubleBuffered(false); setOpaque(true); setDefaultPreferences(); updateUI(); } /** Returns the number of axes to display. Note that this is not necessarily * equal to the number of dimensions in the model. * * @return The number of axes to display. */ public int getNumAxes(){ if (axes != null) return axes.length; else return 0; } /** * Swaps two axes. This means the dimensions assigned to the two axes are swapped. * * @param axis1 The first axis. * @param axis2 The second axis. */ public void swapAxes(int axis1, int axis2){ Axis temp = axes[axis1]; axes[axis1] = axes[axis2]; axes[axis2] = temp; setupPopup(); } /** * Adds an axis to the end of the display. * * @param num The dimension id the new axis should display. */ public void addAxis(int num){ addAxis(num, axes.length); } /** * Inserts a new axis between the two axes defined by targetRegion. * * @param num The dimension id the new axis should display. * @param targetRegion The location of the new axis. 0 puts the new axis in * front of all others. */ public void addAxis(int num, int targetRegion){ Axis newAxes[] = new Axis[axes.length+1]; int i=0, j=0; for (;i<newAxes.length;i++){ if (i == targetRegion){ Axis newAxis = new Axis(num, model.getMinValue(num) - model.getMaxValue(num), model.getMaxValue(num), model.getAxisLabel(num)); newAxes[i] = newAxis; System.out.println("adding axis " + newAxis.label); } else { newAxes[i] = axes[j]; j++; } } axes = newAxes; setupPopup(); deepRepaint = true; repaint(); } /** * Removes an axis from the display. * * @param num The number of the axis to remove. */ public void removeAxis(int num){ Axis newAxes[] = new Axis[axes.length-1]; int i=0,j=0; for (;i<newAxes.length;i++){ if (j == num){ j++; } newAxes[i] = axes[j]; j++; } axes = newAxes; setupPopup(); deepRepaint = true; repaint(); } /** * Sets the model to display. * * @param model The model to display. */ public void setModel(ParallelSpaceModel model){ if (this.model != null) { this.model.removeChangeListener(this); axes = null; brushValues = null; } this.model = model; if (model != null){ model.addChangeListener(this); axes = new Axis[model.getNumDimensions()]; String axisNames[] = new String[model.getNumDimensions()]; brushValues = new float[model.getNumRecords()]; for (int i=0; i<model.getNumDimensions(); i++){ // initialize scaling of axis to show maximum detail Axis newAxis = new Axis(i, model.getMinValue(i) - model.getMaxValue(i), model.getMaxValue(i), model.getAxisLabel(i)); axes[i] = newAxis; axisNames[i] = newAxis.label; } popupMenu.setAvailableAxes(axisNames); popupMenu.setVisibleAxes(axisNames); } if (cFrame != null){ cFrame.updateAxes(); } currentBrush = null; deepRepaint = true; repaint(); } /** * Resets the display. The brush is removed, and the model data is rendered in * its initial state. */ public void resetAll(){ setCurrentBrush(null); setModel(model); setEditMode(REORDER); repaint(); } /** * Sets the mode for user interaction with the display. * * @param mode The interaction mode to use. */ public void setEditMode(int mode){ editMode = mode; resetCursor(); } void resetCursor(){ switch (editMode){ case BRUSH: setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); break; default: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } /** * Returns the currently active interaction mode. * * @return The currently active interaction mode. */ public int getEditMode(){ return editMode; } /** * Returns the model. * Actually the model should be hidden, because of the confusion that might * occur by mistaking axes and dimensions. This requires * a rewrite of some parts of the code, so this is marked to do! * * @return The model that is currently displayed ba the component. */ protected ParallelSpaceModel getModel(){ return model; } /** * Returns the number of Records in the model. */ public int getNumRecords(){ if (model != null) return model.getNumRecords(); else return 0; } public String getRecordLabel(int num){ if (model != null) return model.getRecordLabel(num); else return null; } public float getValue(int recordNum, int axisNum){ if (model != null) { return model.getValue(recordNum, axes[axisNum].dimension); } else { return 0; } } private int brushCount = 0; public float getBrushValue(int num){ if ((currentBrush != null) && (currentBrush.getNumValues() > num)) return currentBrush.getBrushValue(num); else return 0.0f; } public void setBrushValue(int num, float val){ if ((currentBrush != null) && (currentBrush.getNumValues() > num)) currentBrush.setBrushValue(num, val); } /** * Returns the number of records that are currently brushed. */ public int getBrushedCount(){ if (currentBrush != null) return currentBrush.getNumBrushed(); else return 0; } /** Getter for property currentBrush. * @return Value of property currentBrush. */ public Brush getCurrentBrush() { return currentBrush; } /** Setter for property currentBrush. * @param currentBrush New value of property currentBrush. */ public void setCurrentBrush(Brush currentBrush) { this.currentBrush = currentBrush; fireBrushChanged(currentBrush); System.out.println("currentBrush set: " + currentBrush); brushChanged = true; repaint(); } /** * Returns an array with the ids of the records in the given value range. * * @param axisnum The axis the given range is valid for. * @param min The lower boundary of the range (>=). * @param max The upper boundary of the range (<). */ public int[] getRecordsByValueRange(int axisnum, float min, float max){ int ids[] = new int[getNumRecords()]; int count = 0; for (int i=0; i<getNumRecords(); i++){ float val = getValue(i, axisnum); if ((val >= min) && (val < max)) ids[count++] = i; } if (count > 0) { int newids[] = new int[count]; System.arraycopy(ids,0,newids,0,count); return newids; } else return new int[0]; } /** * Returns the number of records in the given value range. * * @param axisnum The axis the given range is valid for. * @param min The lower boundary of the range (>=). * @param max The upper boundary of the range (<). */ public int getNumRecordsInRange(int axisnum, float min, float max){ int count = 0; for (int i=0; i<getNumRecords(); i++){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -