Search in sources :

Example 1 with ListSelectionModel

use of javax.swing.ListSelectionModel in project pcgen by PCGen.

the class AbilityChooserTab method createState.

//
//	private final class AbilityTransferHandler extends TransferHandler
//	{
//
//		private CharacterFacade character;
//
//		public AbilityTransferHandler(CharacterFacade character)
//		{
//			this.character = character;
//		}
//
//		private final DataFlavor abilityFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType +
//				";class=" +
//				AbilityFacade.class.getName(),
//																null);
//
//		@Override
//		public int getSourceActions(JComponent c)
//		{
//			if (selectedAbility != null)
//			{
//				if (selectedTreeViewPanel.isAncestorOf(c))
//				{
//					return MOVE;
//				}
//				if (selectedAbility.isMult())
//				{
//					return COPY;
//				}
//				if (!character.hasAbility(selectedCatagory, selectedAbility))
//				{
//					return MOVE;
//				}
//			}
//			return NONE;
//		}
//
//		@Override
//		protected Transferable createTransferable(JComponent c)
//		{
//			final AbilityFacade transferAbility = selectedAbility;
//			return new Transferable()
//			{
//
//				public DataFlavor[] getTransferDataFlavors()
//				{
//					return new DataFlavor[]
//							{
//								abilityFlavor
//							};
//				}
//
//				public boolean isDataFlavorSupported(DataFlavor flavor)
//				{
//					return abilityFlavor == flavor;
//				}
//
//				public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
//				{
//					if (!isDataFlavorSupported(flavor))
//					{
//						throw new UnsupportedFlavorException(flavor);
//					}
//					return transferAbility;
//				}
//
//			};
//		}
//
//		@Override
//		public boolean canImport(JComponent comp, DataFlavor[] transferFlavors)
//		{
//			return transferFlavors[0] == abilityFlavor;
//		}
//
//		@Override
//		public boolean importData(JComponent comp, Transferable t)
//		{
//			if (selectedTreeViewPanel.isAncestorOf(comp))
//			{
//				try
//				{
//					AbilityFacade ability = (AbilityFacade) t.getTransferData(abilityFlavor);
//					// TODO: add some extra logic
//					character.addAbility(selectedCatagory, ability);
//					return true;
//				}
//				catch (UnsupportedFlavorException ex)
//				{
//					Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
//																			null,
//																			ex);
//				}
//				catch (IOException ex)
//				{
//					Logger.getLogger(AbilityChooserTab.class.getName()).log(Level.SEVERE,
//																			null,
//																			ex);
//				}
//				return false;
//			}
//			return true;
//		}
//
//		@Override
//		protected void exportDone(JComponent source, Transferable data,
//								  int action)
//		{
//			if (action == COPY)
//			{
//				return;
//			}
//		}
//
//	}
public Hashtable<Object, Object> createState(CharacterFacade character, ListFacade<AbilityCategoryFacade> categories, ListFacade<AbilityCategoryFacade> fullCategoryList, String title) {
    Hashtable<Object, Object> state = new Hashtable<>();
    CategoryTableModel categoryTableModel = new CategoryTableModel(character, fullCategoryList, categoryBar, categoryTable);
    state.put(CategoryTableModel.class, categoryTableModel);
    ListSelectionModel listModel = new DefaultListSelectionModel();
    listModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    state.put(ListSelectionModel.class, listModel);
    state.put(AbilityTreeTableModel.class, new AbilityTreeTableModel(character, categories));
    state.put(AvailableAbilityTreeViewModel.class, new AvailableAbilityTreeViewModel(character, fullCategoryList, listModel, title));
    //state.put(AbilityTransferHandler.class, new AbilityTransferHandler(character));
    state.put(InfoHandler.class, new InfoHandler(character, categories));
    state.put(TreeRendererHandler.class, new TreeRendererHandler(character));
    state.put(AddAction.class, new AddAction(character));
    state.put(RemoveAction.class, new RemoveAction(character));
    state.put(AbilityFilterHandler.class, new AbilityFilterHandler(character));
    state.put(CategoryFilterHandler.class, new CategoryFilterHandler(categoryTableModel));
    return state;
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) AbilityTreeTableModel(pcgen.gui2.tabs.ability.AbilityTreeTableModel) Hashtable(java.util.Hashtable) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel)

Example 2 with ListSelectionModel

use of javax.swing.ListSelectionModel in project pcgen by PCGen.

the class DomainInfoTab method initComponents.

private void initComponents() {
    setOrientation(VERTICAL_SPLIT);
    deityTable.setTreeCellRenderer(qualifiedRenderer);
    JPanel panel = new JPanel(new BorderLayout());
    FilterBar<Object, DeityFacade> bar = new FilterBar<>();
    bar.addDisplayableFilter(new SearchFilterPanel());
    //$NON-NLS-1$
    qDeityButton.setText(LanguageBundle.getString("in_igQualFilter"));
    bar.addDisplayableFilter(qDeityButton);
    deityTable.setDisplayableFilter(bar);
    panel.add(bar, BorderLayout.NORTH);
    ListSelectionModel selectionModel = deityTable.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    panel.add(new JScrollPane(deityTable), BorderLayout.CENTER);
    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    //$NON-NLS-1$
    box.add(new JLabel(LanguageBundle.getString("in_domDeityLabel")));
    box.add(Box.createHorizontalStrut(5));
    box.add(selectedDeity);
    box.add(Box.createHorizontalStrut(5));
    box.add(selectDeity);
    box.add(Box.createHorizontalGlue());
    panel.add(box, BorderLayout.SOUTH);
    FlippingSplitPane splitPane = new FlippingSplitPane("DomainTop");
    splitPane.setLeftComponent(panel);
    panel = new JPanel(new BorderLayout());
    FilterBar<CharacterFacade, DomainFacade> dbar = new FilterBar<>();
    dbar.addDisplayableFilter(new SearchFilterPanel());
    //$NON-NLS-1$
    qDomainButton.setText(LanguageBundle.getString("in_igQualFilter"));
    dbar.addDisplayableFilter(qDomainButton);
    domainFilter = dbar;
    panel.add(dbar, BorderLayout.NORTH);
    selectionModel = domainTable.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    domainTable.setAutoCreateColumnsFromModel(false);
    domainTable.setColumnModel(createDomainColumnModel());
    JScrollPane scrollPane = TableUtils.createCheckBoxSelectionPane(domainTable, domainRowHeaderTable);
    panel.add(scrollPane, BorderLayout.CENTER);
    box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    //$NON-NLS-1$
    box.add(new JLabel(LanguageBundle.getString("in_domRemainDomLabel")));
    box.add(Box.createHorizontalStrut(5));
    box.add(selectedDomain);
    box.add(Box.createHorizontalGlue());
    panel.add(box, BorderLayout.SOUTH);
    splitPane.setRightComponent(panel);
    setTopComponent(splitPane);
    splitPane = new FlippingSplitPane("DomainBottom");
    splitPane.setLeftComponent(deityInfo);
    splitPane.setRightComponent(domainInfo);
    setBottomComponent(splitPane);
    setResizeWeight(0.65);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ListSelectionModel(javax.swing.ListSelectionModel) JLabel(javax.swing.JLabel) Box(javax.swing.Box) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) CharacterFacade(pcgen.facade.core.CharacterFacade) DomainFacade(pcgen.facade.core.DomainFacade) FilterBar(pcgen.gui2.filter.FilterBar) BorderLayout(java.awt.BorderLayout) DeityFacade(pcgen.facade.core.DeityFacade) SearchFilterPanel(pcgen.gui2.filter.SearchFilterPanel)

Example 3 with ListSelectionModel

use of javax.swing.ListSelectionModel in project ACS by ACS-Community.

the class JDynAct method buildWindow.

/** Build the GUI
	 *
	 */
private void buildWindow() {
    Container rootCnt = getContentPane();
    rootCnt.setLayout(new BorderLayout());
    // The container with labels and combo boxes
    Container firstCnt = new Container();
    firstCnt.setLayout(new GridLayout(4, 2));
    firstCnt.add(new JLabel("Name"));
    nameCB = new JComboBox();
    nameCB.setEditable(true);
    nameCB.addItem("*");
    nameCB.addItem("PIPPO");
    nameCB.addItem("PLUTO");
    firstCnt.add(nameCB);
    firstCnt.add(new JLabel("IDL interface"));
    idlCB = new JComboBox();
    idlCB.addItem("*");
    idlCB.addItem("IDL:alma/acsexmplLamp/Lamp:1.0");
    idlCB.addItem("IDL:alma/MOUNT_ACS/Mount:1.0");
    idlCB.addItem("IDL:alma/demo/HelloDemo:1.0");
    idlCB.setEditable(true);
    firstCnt.add(idlCB);
    firstCnt.add(new JLabel("Implementation"));
    implCB = new JComboBox();
    implCB.addItem("*");
    implCB.addItem("acsexmplLampImpl");
    implCB.addItem("acsexmplMountImpl");
    implCB.addItem("alma.demo.HelloDemoImpl.HelloDemoHelper");
    implCB.addItem("demoImpl.HelloDemo");
    implCB.addItem("acsexmplHelloWorldClient");
    implCB.setEditable(true);
    firstCnt.add(implCB);
    firstCnt.add(new JLabel("Container"));
    containerCB = new JComboBox();
    containerCB.addItem("*");
    containerCB.addItem("bilboContainer");
    containerCB.addItem("frodoContainer");
    containerCB.addItem("aragornContainer");
    containerCB.setEditable(true);
    firstCnt.add(containerCB);
    // The container with the activate button
    Container secondCnt = new Container();
    secondCnt.setLayout(new FlowLayout());
    JButton activateB = new JButton("Activate");
    activateB.addActionListener(this);
    secondCnt.add(activateB, "Center");
    // The container with activated container
    MyTableModel tableModel = new MyTableModel();
    activatedT = new JTable(tableModel);
    activatedT.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    ListSelectionModel rowSM = activatedT.getSelectionModel();
    JScrollPane scrollP = new JScrollPane(activatedT);
    activatedT.setPreferredScrollableViewportSize(new Dimension(400, 90));
    MyCellRendererr cellR = new MyCellRendererr();
    TableColumnModel tcm = activatedT.getColumnModel();
    TableColumn tc = tcm.getColumn(2);
    tc.setCellRenderer(cellR);
    MyCellEditor cellE = new MyCellEditor(this);
    tc.setCellEditor(cellE);
    Container thirdCnt = new Container();
    thirdCnt.setLayout(new FlowLayout());
    thirdCnt.add(scrollP, "North");
    // Add the container to the main container
    rootCnt.add(firstCnt, "North");
    rootCnt.add(secondCnt, "Center");
    rootCnt.add(thirdCnt, "South");
}
Also used : JScrollPane(javax.swing.JScrollPane) FlowLayout(java.awt.FlowLayout) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ListSelectionModel(javax.swing.ListSelectionModel) TableColumnModel(javax.swing.table.TableColumnModel) Dimension(java.awt.Dimension) TableColumn(javax.swing.table.TableColumn) Container(java.awt.Container) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JTable(javax.swing.JTable)

Example 4 with ListSelectionModel

use of javax.swing.ListSelectionModel in project adempiere by adempiere.

the class MiniTable method doAction.

/**
     * Performs the action.
     * @param e
     * @param actionName determines which action to perform
     * @param dy the number of rows over which to perform the action.
     */
private void doAction(ActionEvent e, String actionName, int dy) {
    int leadRow = 0;
    MiniTable table = (MiniTable) e.getSource();
    if (table.getRowCount() <= 0 || table.getColumnCount() <= 0) {
        // bail - don't try to move selection on an empty table
        return;
    }
    ListSelectionModel rsm = table.getSelectionModel();
    int index = rsm.getLeadSelectionIndex();
    int compare = table.getRowCount();
    if (table.getShowTotals())
        compare = compare - 1;
    index = index < compare ? index : -1;
    if (dy != 0) {
        if (// Up
        dy < 0) {
            //  Check limit at the top
            leadRow = Math.min(Math.max(index + dy, 0), index);
        } else if (// Down
        dy > 0) {
            //  Check the limit at the bottom
            leadRow = Math.min(Math.max(index + dy, 0), compare - 1);
        }
        if (actionName.equals("SelectRowUp") || actionName.equals("SelectRowDown")) {
            rsm.clearSelection();
            rsm.addSelectionInterval(leadRow, leadRow);
            matchCheckWithSelectedRows();
        } else if (actionName.equals("AddRowUp") || actionName.equals("AddRowDown")) {
            // Determine if the focused row is selected
            //  Test the first row
            Object data = table.getValueAt(index, table.convertColumnIndexToView(getKeyColumnIndex()));
            if (data instanceof IDColumn) {
                rsm.addSelectionInterval(index, leadRow);
                setRowChecked(index, true);
                setRowChecked(leadRow, true);
            }
        } else if (actionName.equals("AddRowUpExtend") || actionName.equals("AddRowDownExtend")) {
            table.changeSelection(index, 0, false, true);
            table.changeSelection(leadRow, 0, false, true);
            matchCheckWithSelectedRows();
        } else if (actionName.equals("ChangeLeadUp") || actionName.equals("ChangeLeadDown")) {
            // Determine if the focused row is selected
            if (isRowChecked(index)) {
                //  Select the original row			
                rsm.addSelectionInterval(index, index);
            } else if (!isRowChecked(index) && table.isRowSelected(index)) {
                rsm.removeSelectionInterval(index, index);
            }
            ((DefaultListSelectionModel) rsm).moveLeadSelectionIndex(leadRow);
        }
    }
    Rectangle cellRect = table.getCellRect(leadRow, 0, false);
    if (cellRect != null) {
        table.scrollRectToVisible(cellRect);
    }
}
Also used : Rectangle(java.awt.Rectangle) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel)

Example 5 with ListSelectionModel

use of javax.swing.ListSelectionModel in project adempiere by adempiere.

the class MiniTable method toggleRowCheckedBySelection.

/**
     * Toggles the ID selection of the selected rows.  Multi-selection only.
     */
private void toggleRowCheckedBySelection() {
    if (isMultiSelection()) {
        ListSelectionModel rsm = this.getSelectionModel();
        int leadRow = rsm.getLeadSelectionIndex();
        int[] selectedRows = this.getSelectedRows();
        // Limit the number of row selection events to once per change
        if (selectedRows.length > 1)
            m_changingMultipleRows = true;
        else
            m_changingMultipleRows = false;
        for (int row : selectedRows) {
            toggleRowChecked(row);
        }
        //  Return the lead to its original location
        rsm.setLeadSelectionIndex(leadRow);
        if (m_changingMultipleRows) {
            fireRowSelectionEvent();
            m_changingMultipleRows = false;
        }
    }
}
Also used : DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel)

Aggregations

ListSelectionModel (javax.swing.ListSelectionModel)76 BorderLayout (java.awt.BorderLayout)20 Dimension (java.awt.Dimension)20 JButton (javax.swing.JButton)20 JPanel (javax.swing.JPanel)19 ActionEvent (java.awt.event.ActionEvent)17 ListSelectionEvent (javax.swing.event.ListSelectionEvent)17 ListSelectionListener (javax.swing.event.ListSelectionListener)17 Point (java.awt.Point)16 ActionListener (java.awt.event.ActionListener)16 JTable (javax.swing.JTable)16 JScrollPane (javax.swing.JScrollPane)15 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)13 MouseEvent (java.awt.event.MouseEvent)12 TableColumn (javax.swing.table.TableColumn)12 Insets (java.awt.Insets)11 MouseAdapter (java.awt.event.MouseAdapter)11 TableModel (javax.swing.table.TableModel)11 TableRowSorter (javax.swing.table.TableRowSorter)10 FlowLayout (java.awt.FlowLayout)9