Search in sources :

Example 66 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project vcell by virtualcell.

the class PDEDataViewer method roiAction.

private void roiAction() {
    BeanUtils.setCursorThroughout(this, Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try {
        final String[] ROI_COLUMN_NAMES = new String[] { "ROI source", "ROI source name", "ROI Description" };
        final Vector<Object> auxInfoV = new Vector<Object>();
        final DataIdentifier dataIdentifier = getPdeDataContext().getDataIdentifier();
        VariableType variableType = dataIdentifier.getVariableType();
        final boolean isVolume = variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.VOLUME_REGION);
        DefaultTableModel tableModel = new DefaultTableModel() {

            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        for (int i = 0; i < ROI_COLUMN_NAMES.length; i++) {
            tableModel.addColumn(ROI_COLUMN_NAMES[i]);
        }
        // Add Snapshot ROI
        if ((isVolume ? volumeSnapshotROI : membraneSnapshotROI) != null) {
            tableModel.addRow(new Object[] { (isVolume ? "Volume" : "Membrane") + " Variables and Functions", "Snapshot", (isVolume ? volumeSnapshotROIDescription : membraneSnapshotROIDescription) + ", (values = 1.0)" });
            auxInfoV.add((isVolume ? volumeSnapshotROI : membraneSnapshotROI));
        }
        // Add user ROIs
        SpatialSelection[] userROIArr = getPDEDataContextPanel1().fetchSpatialSelections(true, false);
        for (int i = 0; userROIArr != null && i < userROIArr.length; i += 1) {
            String descr = null;
            boolean bPoint = false;
            if (isVolume) {
                if (userROIArr[i] instanceof SpatialSelectionVolume) {
                    Curve curve = ((SpatialSelectionVolume) userROIArr[i]).getCurveSelectionInfo().getCurve();
                    descr = curve.getDescription();
                    if (curve instanceof SinglePoint) {
                        bPoint = true;
                    }
                }
            } else {
                if (userROIArr[i] instanceof SpatialSelectionMembrane) {
                    SampledCurve selectionSource = ((SpatialSelectionMembrane) userROIArr[i]).getSelectionSource();
                    descr = selectionSource.getDescription();
                    if (selectionSource instanceof SinglePoint) {
                        bPoint = true;
                    }
                }
            }
            // Add Area User ROI
            BitSet fillBitSet = null;
            if (userROIArr[i] instanceof SpatialSelectionVolume) {
                fillBitSet = getFillROI((SpatialSelectionVolume) userROIArr[i]);
                if (fillBitSet != null) {
                    tableModel.addRow(new Object[] { "User Defined", descr, "Area Enclosed Volume ROI" });
                    auxInfoV.add(fillBitSet);
                }
            }
            // Add Point and Line User ROI
            if (fillBitSet == null) {
                tableModel.addRow(new Object[] { "User Defined", descr, (bPoint ? "Point" : "Line") + (isVolume ? " Volume" : " Membrane") + " ROI " });
                auxInfoV.add(userROIArr[i]);
            }
        }
        // Add sorted Geometry ROI
        final CartesianMesh cartesianMesh = getPdeDataContext().getCartesianMesh();
        HashMap<Integer, ?> regionMapSubvolumesHashMap = (isVolume ? cartesianMesh.getVolumeRegionMapSubvolume() : cartesianMesh.getMembraneRegionMapSubvolumesInOut());
        Set<?> regionMapSubvolumesEntrySet = regionMapSubvolumesHashMap.entrySet();
        Iterator<?> regionMapSubvolumesEntryIter = regionMapSubvolumesEntrySet.iterator();
        TreeSet<Object[]> sortedGeomROITreeSet = new TreeSet<Object[]>(new Comparator<Object[]>() {

            public int compare(Object[] o1, Object[] o2) {
                int result = ((String) ((Object[]) o1[0])[1]).compareToIgnoreCase((String) ((Object[]) o2[0])[1]);
                if (result == 0) {
                    result = (((Entry<Integer, ?>) o1[1]).getKey()).compareTo(((Entry<Integer, ?>) o2[1]).getKey());
                }
                return result;
            }
        });
        while (regionMapSubvolumesEntryIter.hasNext()) {
            Entry<Integer, ?> regionMapSubvolumesEntry = (Entry<Integer, ?>) regionMapSubvolumesEntryIter.next();
            sortedGeomROITreeSet.add(new Object[] { new Object[] { "Geometry", (isVolume ? getSimulationModelInfo().getVolumeNamePhysiology(((Integer) regionMapSubvolumesEntry.getValue())) : getSimulationModelInfo().getMembraneName(((int[]) regionMapSubvolumesEntry.getValue())[0], ((int[]) regionMapSubvolumesEntry.getValue())[1], false)), (isVolume ? "(svID=" + regionMapSubvolumesEntry.getValue() + " " : "(") + "vrID=" + regionMapSubvolumesEntry.getKey() + ") Predefined " + (isVolume ? "volume" : "membrane") + " region" }, regionMapSubvolumesEntry });
        }
        Iterator<Object[]> sortedGeomROIIter = sortedGeomROITreeSet.iterator();
        while (sortedGeomROIIter.hasNext()) {
            Object[] sortedGeomROIObjArr = (Object[]) sortedGeomROIIter.next();
            tableModel.addRow((Object[]) sortedGeomROIObjArr[0]);
            auxInfoV.add(sortedGeomROIObjArr[1]);
        }
        final ScrollTable roiTable = new ScrollTable();
        roiTable.setModel(tableModel);
        roiTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        roiTable.setPreferredScrollableViewportSize(new Dimension(500, 200));
        final JPanel mainJPanel = new JPanel();
        BoxLayout mainBL = new BoxLayout(mainJPanel, BoxLayout.Y_AXIS);
        mainJPanel.setLayout(mainBL);
        MiniTimePanel timeJPanel = new MiniTimePanel();
        ActionListener okAction = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (((Double) timeJPanel.jcb_time_begin.getSelectedItem()).compareTo((Double) timeJPanel.jcb_time_end.getSelectedItem()) > 0) {
                    PopupGenerator.showErrorDialog(PDEDataViewer.this, "Selected 'Begin Time' must be less than or equal to 'End Time'");
                    return;
                }
                int[] selectedRows = roiTable.getSelectedRows();
                if (selectedRows != null) {
                    try {
                        BitSet dataBitSet = new BitSet(getPdeDataContext().getDataValues().length);
                        for (int i = 0; i < selectedRows.length; i++) {
                            Object auxInfo = auxInfoV.elementAt(selectedRows[i]);
                            if (auxInfo instanceof BitSet) {
                                dataBitSet.or((BitSet) auxInfo);
                            } else if (auxInfo instanceof SpatialSelectionMembrane) {
                                int[] roiIndexes = ((SpatialSelectionMembrane) auxInfo).getIndexSamples().getSampledIndexes();
                                for (int j = 0; j < roiIndexes.length; j += 1) {
                                    dataBitSet.set(roiIndexes[j], true);
                                }
                            } else if (auxInfo instanceof SpatialSelectionVolume) {
                                int[] roiIndexes = ((SpatialSelectionVolume) auxInfo).getIndexSamples(0, 1).getSampledIndexes();
                                for (int j = 0; j < roiIndexes.length; j += 1) {
                                    dataBitSet.set(roiIndexes[j], true);
                                }
                            } else if (auxInfo instanceof Entry) {
                                Entry<Integer, Integer> entry = (Entry<Integer, Integer>) auxInfo;
                                if (isVolume) {
                                    int volumeRegionID = entry.getKey();
                                    dataBitSet.or(cartesianMesh.getVolumeROIFromVolumeRegionID(volumeRegionID));
                                } else {
                                    int membraneRegionID = entry.getKey();
                                    dataBitSet.or(cartesianMesh.getMembraneROIFromMembraneRegionID(membraneRegionID));
                                }
                            } else if (auxInfo instanceof BitSet) {
                                dataBitSet.or((BitSet) auxInfo);
                            } else {
                                throw new Exception("ROI table, Unknown data type: " + auxInfo.getClass().getName());
                            }
                        }
                        TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifier.getName() }, new BitSet[] { dataBitSet }, ((Double) timeJPanel.jcb_time_begin.getSelectedItem()).doubleValue(), 1, ((Double) timeJPanel.jcb_time_end.getSelectedItem()).doubleValue(), true, false, VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
                        Hashtable<String, Object> hash = new Hashtable<String, Object>();
                        hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
                        AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieve data for '" + dataIdentifier + "'", PDEDataViewer.this, getPdeDataContext());
                        AsynchClientTask task2 = new AsynchClientTask("Showing stat for '" + dataIdentifier + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                            @Override
                            public void run(Hashtable<String, Object> hashTable) throws Exception {
                                TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) hashTable.get(StringKey_timeSeriesJobResults);
                                plotSpaceStats(tsJobResultsSpaceStats);
                            }
                        };
                        ClientTaskDispatcher.dispatch(PDEDataViewer.this, hash, new AsynchClientTask[] { task1, task2 }, true, true, null);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                        PopupGenerator.showErrorDialog(PDEDataViewer.this, "ROI Error.\n" + e1.getMessage(), e1);
                    }
                }
                BeanUtils.disposeParentWindow(mainJPanel);
            }
        };
        ActionListener cancelAction = new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                BeanUtils.disposeParentWindow(mainJPanel);
            }
        };
        OkCancelSubPanel okCancelJPanel = new OkCancelSubPanel(okAction, cancelAction);
        roiTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                if (roiTable.getSelectedRows() != null && roiTable.getSelectedRows().length > 0) {
                    okCancelJPanel.okButton.setEnabled(true);
                } else {
                    okCancelJPanel.okButton.setEnabled(false);
                }
            }
        });
        mainJPanel.add(timeJPanel);
        mainJPanel.add(roiTable.getEnclosingScrollPane());
        mainJPanel.add(okCancelJPanel);
        // showComponentInFrame(mainJPanel,
        // "Calculate "+(isVolume?"volume":"membrane")+" statistics for '"+getPdeDataContext().getVariableName()+"'."+
        // "  Choose times and 1 or more ROI(s).");
        Frame dialogOwner = JOptionPane.getFrameForComponent(this);
        JOptionPane inputDialog = new JOptionPane(mainJPanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[0]);
        final JDialog d = inputDialog.createDialog(dialogOwner, "Calculate " + (isVolume ? "volume" : "membrane") + " statistics for '" + getPdeDataContext().getVariableName() + "'." + "  Choose times and 1 or more ROI(s).");
        d.setResizable(true);
        try {
            DialogUtils.showModalJDialogOnTop(d, PDEDataViewer.this);
        } finally {
            d.dispose();
        }
    } finally {
        BeanUtils.setCursorThroughout(this, Cursor.getDefaultCursor());
    }
}
Also used : JPanel(javax.swing.JPanel) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ScrollTable(org.vcell.util.gui.ScrollTable) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ActionEvent(java.awt.event.ActionEvent) TreeSet(java.util.TreeSet) Vector(java.util.Vector) SampledCurve(cbit.vcell.geometry.SampledCurve) Curve(cbit.vcell.geometry.Curve) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) JOptionPane(javax.swing.JOptionPane) ListSelectionListener(javax.swing.event.ListSelectionListener) CartesianMesh(cbit.vcell.solvers.CartesianMesh) ActionListener(java.awt.event.ActionListener) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) JDialog(javax.swing.JDialog) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Frame(java.awt.Frame) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) DefaultTableModel(javax.swing.table.DefaultTableModel) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Entry(java.util.Map.Entry) UserDataEntry(cbit.vcell.export.gloworm.atoms.UserDataEntry) SinglePoint(cbit.vcell.geometry.SinglePoint) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SampledCurve(cbit.vcell.geometry.SampledCurve) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) Dimension(java.awt.Dimension) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException)

Example 67 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project vcell by virtualcell.

the class VFrap_ROIAssistPanel method showComponentOKCancelTableList.

public int[] showComponentOKCancelTableList(final Component requester, String title, String[] columnNames, Object[][] rowData, int listSelectionModel_SelectMode, final RegionInfo[] regionInfoArr, final short[] multiObjectROIPixels) throws UserCancelException {
    DefaultTableModel tableModel = new DefaultTableModel() {

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tableModel.setDataVector(rowData, columnNames);
    final JTable table = new JTable(tableModel);
    table.setSelectionMode(listSelectionModel_SelectMode);
    JScrollPane scrollPane = new JScrollPane(table);
    table.setPreferredScrollableViewportSize(new Dimension(500, 250));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                try {
                    int index = table.getSelectedRow();
                    // System.out.println("list index="+index);
                    RegionInfo keepRegion = regionInfoArr[index];
                    short[] removePixels = multiObjectROIPixels.clone();
                    for (int i = 0; i < removePixels.length; i++) {
                        if (!keepRegion.isIndexInRegion(i)) {
                            removePixels[i] = 0;
                        }
                    }
                    UShortImage ushortImage = new UShortImage(removePixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
                    final ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
                    frapData.addReplaceRoi(newCellROI);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    throw new RuntimeException("Error selecting resolved ROI", e2);
                }
            }
        }
    });
    ScopedExpressionTableCellRenderer.formatTableCellSizes(table);
    int result = DialogUtils.showComponentOKCancelDialog(requester, scrollPane, title);
    if (result != JOptionPane.OK_OPTION) {
        throw UserCancelException.CANCEL_GENERIC;
    }
    return table.getSelectedRows();
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultTableModel(javax.swing.table.DefaultTableModel) JTable(javax.swing.JTable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Dimension(java.awt.Dimension) ROI(cbit.vcell.VirtualMicroscopy.ROI) UserCancelException(org.vcell.util.UserCancelException) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 68 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project libgdx by libgdx.

the class TemplatePickerPanel method initializeComponents.

protected void initializeComponents(Class<T> type, LoaderButton<T> loaderButton) {
    int i = 0;
    if (loaderButton != null) {
        loaderButton.setListener(this);
        contentPanel.add(loaderButton, new GridBagConstraints(0, i++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
    }
    JScrollPane scroll = new JScrollPane();
    contentPanel.add(scroll, new GridBagConstraints(0, i, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
    {
        templatesTable = new JTable() {

            public Class getColumnClass(int column) {
                return column == 1 ? Boolean.class : super.getColumnClass(column);
            }

            @Override
            public Dimension getPreferredScrollableViewportSize() {
                Dimension dim = super.getPreferredScrollableViewportSize();
                dim.height = getPreferredSize().height;
                return dim;
            }
        };
        templatesTable.getTableHeader().setReorderingAllowed(false);
        templatesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        scroll.setViewportView(templatesTable);
        templatesTableModel = new DefaultTableModel(new String[0][0], new String[] { "Template", "Selected" });
        templatesTable.setModel(templatesTableModel);
        reloadTemplates();
        templatesTableModel.addTableModelListener(new TableModelListener() {

            public void tableChanged(TableModelEvent event) {
                if (event.getColumn() != 1)
                    return;
                int row = event.getFirstRow();
                boolean checked = (Boolean) templatesTable.getValueAt(row, 1);
                if (isOneModelSelectedRequired && (value.size == 1 && !checked)) {
                    EditorPanel.setValue(templatesTableModel, true, row, 1);
                    return;
                }
                templateChecked(row, checked);
            }
        });
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) TableModelEvent(javax.swing.event.TableModelEvent) JTable(javax.swing.JTable) DefaultTableModel(javax.swing.table.DefaultTableModel) TableModelListener(javax.swing.event.TableModelListener) Dimension(java.awt.Dimension)

Example 69 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project libgdx by libgdx.

the class EffectPanel method initializeComponents.

private void initializeComponents() {
    setLayout(new GridBagLayout());
    {
        JScrollPane scroll = new JScrollPane();
        add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
        {
            emitterTable = new JTable() {

                public Class getColumnClass(int column) {
                    return column == 1 ? Boolean.class : super.getColumnClass(column);
                }

                @Override
                public Dimension getPreferredScrollableViewportSize() {
                    Dimension dim = super.getPreferredScrollableViewportSize();
                    dim.height = getPreferredSize().height;
                    return dim;
                }
            };
            emitterTable.getTableHeader().setReorderingAllowed(false);
            emitterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            scroll.setViewportView(emitterTable);
            emitterTableModel = new DefaultTableModel(new String[0][0], new String[] { "Emitter", "" });
            emitterTable.setModel(emitterTableModel);
            emitterTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                public void valueChanged(ListSelectionEvent event) {
                    if (event.getValueIsAdjusting())
                        return;
                    emitterSelected();
                }
            });
            emitterTableModel.addTableModelListener(new TableModelListener() {

                public void tableChanged(TableModelEvent event) {
                    if (event.getColumn() != 1)
                        return;
                    emitterChecked(event.getFirstRow(), (Boolean) emitterTable.getValueAt(event.getFirstRow(), 1));
                }
            });
        }
    }
    {
        JPanel sideButtons = new JPanel(new GridBagLayout());
        add(sideButtons, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        {
            controllerTypeCombo = new JComboBox();
            controllerTypeCombo.setModel(new DefaultComboBoxModel(ControllerType.values()));
            sideButtons.add(controllerTypeCombo, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
        }
        {
            JButton newButton = new JButton("New");
            sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            newButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    ControllerType item = (ControllerType) controllerTypeCombo.getSelectedItem();
                    createDefaultEmitter(item, true, true);
                }
            });
        }
        {
            JButton deleteButton = new JButton("Delete");
            sideButtons.add(deleteButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            deleteButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    deleteEmitter();
                }
            });
        }
        {
            JButton cloneButton = new JButton("Clone");
            sideButtons.add(cloneButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            cloneButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    cloneEmitter();
                }
            });
        }
        {
            sideButtons.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
        }
        {
            JButton saveButton = new JButton("Save");
            sideButtons.add(saveButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            saveButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    saveEffect();
                }
            });
        }
        {
            JButton openButton = new JButton("Open");
            sideButtons.add(openButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            openButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    openEffect();
                }
            });
        }
        {
            JButton importButton = new JButton("Import");
            sideButtons.add(importButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
            importButton.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent event) {
                    importEffect();
                }
            });
        }
    /*
			{
				JButton importButton = new JButton("Export");
				sideButtons.add(importButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER,
					GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
				importButton.addActionListener(new ActionListener() {
					public void actionPerformed (ActionEvent event) {
						exportEffect();
					}
				});
			}
			*/
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) TableModelEvent(javax.swing.event.TableModelEvent) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ControllerType(com.badlogic.gdx.tools.flame.FlameMain.ControllerType) JSeparator(javax.swing.JSeparator) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) TableModelListener(javax.swing.event.TableModelListener)

Example 70 with DefaultTableModel

use of javax.swing.table.DefaultTableModel in project Smack by igniterealtime.

the class EnhancedDebugger method addBasicPanels.

private void addBasicPanels() {
    JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    allPane.setOneTouchExpandable(true);
    messagesTable = new DefaultTableModel(new Object[] { "Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From" }, 0) {

        // CHECKSTYLE:OFF
        private static final long serialVersionUID = 8136121224474217264L;

        @Override
        public boolean isCellEditable(int rowIndex, int mColIndex) {
            // CHECKSTYLE:ON
            return false;
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            if (columnIndex == 2 || columnIndex == 3) {
                return Icon.class;
            }
            return super.getColumnClass(columnIndex);
        }
    };
    JTable table = new JTable(messagesTable);
    // Allow only single a selection
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Hide the first column
    table.getColumnModel().getColumn(0).setMaxWidth(0);
    table.getColumnModel().getColumn(0).setMinWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
    table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
    // Set the column "timestamp" size
    table.getColumnModel().getColumn(1).setMaxWidth(300);
    table.getColumnModel().getColumn(1).setPreferredWidth(90);
    // Set the column "direction" icon size
    table.getColumnModel().getColumn(2).setMaxWidth(50);
    table.getColumnModel().getColumn(2).setPreferredWidth(30);
    // Set the column "packet type" icon size
    table.getColumnModel().getColumn(3).setMaxWidth(50);
    table.getColumnModel().getColumn(3).setPreferredWidth(30);
    // Set the column "Id" size
    table.getColumnModel().getColumn(5).setMaxWidth(100);
    table.getColumnModel().getColumn(5).setPreferredWidth(55);
    // Set the column "type" size
    table.getColumnModel().getColumn(6).setMaxWidth(200);
    table.getColumnModel().getColumn(6).setPreferredWidth(50);
    // Set the column "to" size
    table.getColumnModel().getColumn(7).setMaxWidth(300);
    table.getColumnModel().getColumn(7).setPreferredWidth(90);
    // Set the column "from" size
    table.getColumnModel().getColumn(8).setMaxWidth(300);
    table.getColumnModel().getColumn(8).setPreferredWidth(90);
    // Create a table listener that listen for row selection events
    SelectionListener selectionListener = new SelectionListener(table);
    table.getSelectionModel().addListSelectionListener(selectionListener);
    table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
    allPane.setTopComponent(new JScrollPane(table));
    messageTextArea = new JTextArea();
    messageTextArea.setEditable(false);
    // Add pop-up menu.
    JPopupMenu menu = new JPopupMenu();
    JMenuItem menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(messageTextArea.getText()), null);
        }
    });
    menu.add(menuItem1);
    // Add listener to the text area so the popup menu can come up.
    messageTextArea.addMouseListener(new PopupListener(menu));
    // CHECKSTYLE:OFF
    JPanel sublayout = new JPanel(new BorderLayout());
    sublayout.add(new JScrollPane(messageTextArea), BorderLayout.CENTER);
    JButton clearb = new JButton("Clear All Packets");
    clearb.addActionListener(new AbstractAction() {

        private static final long serialVersionUID = -8576045822764763613L;

        @Override
        public void actionPerformed(ActionEvent e) {
            messagesTable.setRowCount(0);
        }
    });
    // CHECKSTYLE:ON
    sublayout.add(clearb, BorderLayout.NORTH);
    allPane.setBottomComponent(sublayout);
    allPane.setDividerLocation(150);
    tabbedPane.add("All Packets", allPane);
    tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");
    // Create UI elements for client generated XML traffic.
    final JTextArea sentText = new JTextArea();
    sentText.setWrapStyleWord(true);
    sentText.setLineWrap(true);
    sentText.setEditable(false);
    sentText.setForeground(new Color(112, 3, 3));
    tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText));
    tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets");
    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(sentText.getText()), null);
        }
    });
    JMenuItem menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            sentText.setText("");
        }
    });
    // Add listener to the text area so the popup menu can come up.
    sentText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);
    // Create UI elements for server generated XML traffic.
    final JTextArea receivedText = new JTextArea();
    receivedText.setWrapStyleWord(true);
    receivedText.setLineWrap(true);
    receivedText.setEditable(false);
    receivedText.setForeground(new Color(6, 76, 133));
    tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText));
    tabbedPane.setToolTipTextAt(2, "Raw text of the received packets before Smack process them");
    // Add pop-up menu.
    menu = new JPopupMenu();
    menuItem1 = new JMenuItem("Copy");
    menuItem1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // Get the clipboard
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            // Set the sent text as the new content of the clipboard
            clipboard.setContents(new StringSelection(receivedText.getText()), null);
        }
    });
    menuItem2 = new JMenuItem("Clear");
    menuItem2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            receivedText.setText("");
        }
    });
    // Add listener to the text area so the popup menu can come up.
    receivedText.addMouseListener(new PopupListener(menu));
    menu.add(menuItem1);
    menu.add(menuItem2);
    // Create a special Reader that wraps the main Reader and logs data to the GUI.
    ObservableReader debugReader = new ObservableReader(reader);
    readerListener = new ReaderListener() {

        @Override
        public void read(final String str) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                        // Do not add content if the parent is not visible
                        return;
                    }
                    int index = str.lastIndexOf(">");
                    if (index != -1) {
                        if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                            try {
                                receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
                            } catch (BadLocationException e) {
                                LOGGER.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
                            }
                        }
                        receivedText.append(str.substring(0, index + 1));
                        receivedText.append(NEWLINE);
                        if (str.length() > index) {
                            receivedText.append(str.substring(index + 1));
                        }
                    } else {
                        receivedText.append(str);
                    }
                }
            });
        }
    };
    debugReader.addReaderListener(readerListener);
    // Create a special Writer that wraps the main Writer and logs data to the GUI.
    ObservableWriter debugWriter = new ObservableWriter(writer);
    writerListener = new WriterListener() {

        @Override
        public void write(final String str) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && !EnhancedDebuggerWindow.getInstance().isVisible()) {
                        // Do not add content if the parent is not visible
                        return;
                    }
                    if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
                        try {
                            sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
                        } catch (BadLocationException e) {
                            LOGGER.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
                        }
                    }
                    sentText.append(str);
                    if (str.endsWith(">")) {
                        sentText.append(NEWLINE);
                    }
                }
            });
        }
    };
    debugWriter.addWriterListener(writerListener);
    // Assign the reader/writer objects to use the debug versions. The packet reader
    // and writer will use the debug versions when they are created.
    reader = debugReader;
    writer = debugWriter;
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) JButton(javax.swing.JButton) StringSelection(java.awt.datatransfer.StringSelection) BorderLayout(java.awt.BorderLayout) ObservableWriter(org.jivesoftware.smack.util.ObservableWriter) JMenuItem(javax.swing.JMenuItem) ReaderListener(org.jivesoftware.smack.util.ReaderListener) AbstractAction(javax.swing.AbstractAction) JScrollPane(javax.swing.JScrollPane) ObservableReader(org.jivesoftware.smack.util.ObservableReader) Color(java.awt.Color) WriterListener(org.jivesoftware.smack.util.WriterListener) JPopupMenu(javax.swing.JPopupMenu) ActionListener(java.awt.event.ActionListener) JTable(javax.swing.JTable) Clipboard(java.awt.datatransfer.Clipboard) JSplitPane(javax.swing.JSplitPane) BadLocationException(javax.swing.text.BadLocationException) ListSelectionListener(javax.swing.event.ListSelectionListener)

Aggregations

DefaultTableModel (javax.swing.table.DefaultTableModel)139 JTable (javax.swing.JTable)18 Dimension (java.awt.Dimension)14 Vector (java.util.Vector)14 JScrollPane (javax.swing.JScrollPane)14 TableColumn (javax.swing.table.TableColumn)12 JBTable (com.intellij.ui.table.JBTable)10 Point (java.awt.Point)10 ActionEvent (java.awt.event.ActionEvent)9 JPanel (javax.swing.JPanel)9 ListSelectionEvent (javax.swing.event.ListSelectionEvent)9 ListSelectionListener (javax.swing.event.ListSelectionListener)9 JButton (javax.swing.JButton)8 ActionListener (java.awt.event.ActionListener)7 WebAppDetails (com.microsoft.azuretools.utils.WebAppUtils.WebAppDetails)6 Color (java.awt.Color)6 ArrayList (java.util.ArrayList)6 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5