Search in sources :

Example 71 with JComponent

use of javax.swing.JComponent in project JMRI by JMRI.

the class RosterFrame method createTop.

JComponent createTop() {
    Object selectedRosterGroup = prefsMgr.getProperty(getWindowFrameRef(), SELECTED_ROSTER_GROUP);
    groups = new RosterGroupsPanel((selectedRosterGroup != null) ? selectedRosterGroup.toString() : null);
    groups.setNewWindowMenuAction(this.getNewWindowAction());
    setTitle(groups.getSelectedRosterGroup());
    final JPanel rosters = new JPanel();
    rosters.setLayout(new BorderLayout());
    // set up roster table
    rtable = new RosterTable(true, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    rtable.setRosterGroup(this.getSelectedRosterGroup());
    rtable.setRosterGroupSource(groups);
    rosters.add(rtable, BorderLayout.CENTER);
    // add selection listener
    rtable.getTable().getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
        JTable table = rtable.getTable();
        if (!e.getValueIsAdjusting()) {
            if (rtable.getSelectedRosterEntries().length == 1 && table.getSelectedRow() >= 0) {
                log.debug("Selected row ", table.getSelectedRow());
                locoSelected(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRow()), RosterTableModel.IDCOL).toString());
            } else if (rtable.getSelectedRosterEntries().length > 1 || table.getSelectedRow() < 0) {
                locoSelected(null);
            }
        // leave last selected item visible if no selection
        }
    });
    //Set all the sort and width details of the table first.
    String rostertableref = getWindowFrameRef() + ":roster";
    rtable.getTable().setName(rostertableref);
    // Allow only one column to be sorted at a time - 
    // Java allows multiple column sorting, but to effectly persist that, we
    // need to be intelligent about which columns can be meaningfully sorted
    // with other columns; this bypasses the problem by only allowing the
    // last column sorted to affect sorting
    RowSorterUtil.addSingleSortableColumnListener(rtable.getTable().getRowSorter());
    // Reset and then persist the table's ui state
    JTablePersistenceManager tpm = InstanceManager.getNullableDefault(JTablePersistenceManager.class);
    if (tpm != null) {
        tpm.resetState(rtable.getTable());
        tpm.persist(rtable.getTable());
    }
    rtable.getTable().setDragEnabled(true);
    rtable.getTable().setTransferHandler(new TransferHandler() {

        @Override
        public int getSourceActions(JComponent c) {
            return TransferHandler.COPY;
        }

        @Override
        public Transferable createTransferable(JComponent c) {
            JTable table = rtable.getTable();
            ArrayList<String> Ids = new ArrayList<>(table.getSelectedRowCount());
            for (int i = 0; i < table.getSelectedRowCount(); i++) {
                Ids.add(rtable.getModel().getValueAt(table.getRowSorter().convertRowIndexToModel(table.getSelectedRows()[i]), RosterTableModel.IDCOL).toString());
            }
            return new RosterEntrySelection(Ids);
        }

        @Override
        public void exportDone(JComponent c, Transferable t, int action) {
        // nothing to do
        }
    });
    MouseListener rosterMouseListener = new rosterPopupListener();
    rtable.getTable().addMouseListener(rosterMouseListener);
    try {
        clickDelay = ((Integer) Toolkit.getDefaultToolkit().getDesktopProperty("awt.multiClickInterval"));
    } catch (RuntimeException e) {
        clickDelay = 500;
        log.debug("Unable to get the double click speed, Using JMRI default of half a second" + e.toString());
    }
    // assemble roster/groups splitpane
    rosterGroupSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, groups, rosters);
    rosterGroupSplitPane.setOneTouchExpandable(true);
    // emphasis rosters
    rosterGroupSplitPane.setResizeWeight(0);
    Object w = prefsMgr.getProperty(getWindowFrameRef(), "rosterGroupPaneDividerLocation");
    if (w != null) {
        groupSplitPaneLocation = (Integer) w;
        rosterGroupSplitPane.setDividerLocation(groupSplitPaneLocation);
    }
    if (!Roster.getDefault().getRosterGroupList().isEmpty()) {
        if (prefsMgr.getSimplePreferenceState(this.getClass().getName() + ".hideGroups")) {
            hideGroupsPane(true);
        }
    } else {
        enableRosterGroupMenuItems(false);
    }
    PropertyChangeListener propertyChangeListener = (PropertyChangeEvent changeEvent) -> {
        JSplitPane sourceSplitPane = (JSplitPane) changeEvent.getSource();
        String propertyName = changeEvent.getPropertyName();
        if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
            int current = sourceSplitPane.getDividerLocation();
            hideGroups = current <= 1;
            Integer last = (Integer) changeEvent.getNewValue();
            if (current >= 2) {
                groupSplitPaneLocation = current;
            } else if (last >= 2) {
                groupSplitPaneLocation = last;
            }
        }
    };
    groups.addPropertyChangeListener(SELECTED_ROSTER_GROUP, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent pce) {
            prefsMgr.setProperty(this.getClass().getName(), SELECTED_ROSTER_GROUP, pce.getNewValue());
            setTitle((String) pce.getNewValue());
        }
    });
    rosterGroupSplitPane.addPropertyChangeListener(propertyChangeListener);
    Roster.getDefault().addPropertyChangeListener((PropertyChangeEvent e) -> {
        if (e.getPropertyName().equals("RosterGroupAdded") && Roster.getDefault().getRosterGroupList().size() == 1) {
            // if the pane is hidden, show it when 1st group is created
            hideGroupsPane(false);
            enableRosterGroupMenuItems(true);
        } else if (!rtable.isVisible() && (e.getPropertyName().equals("saved"))) {
            if (firstHelpLabel != null) {
                firstHelpLabel.setVisible(false);
            }
            rtable.setVisible(true);
            rtable.resetColumnWidths();
        }
    });
    if (Roster.getDefault().numEntries() == 0) {
        try {
            BufferedImage myPicture = ImageIO.read(FileUtil.findURL(("resources/" + Bundle.getMessage("ThrottleFirstUseImage")), FileUtil.Location.INSTALLED));
            //rosters.add(new JLabel(new ImageIcon( myPicture )), BorderLayout.CENTER);
            firstHelpLabel = new JLabel(new ImageIcon(myPicture));
            rtable.setVisible(false);
            rosters.add(firstHelpLabel, BorderLayout.NORTH);
            //tableArea.add(firstHelpLabel);
            rtable.setVisible(false);
        } catch (IOException ex) {
        // handle exception...
        }
    }
    return rosterGroupSplitPane;
}
Also used : RosterEntrySelection(jmri.util.datatransfer.RosterEntrySelection) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) PropertyChangeListener(java.beans.PropertyChangeListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) JLabel(javax.swing.JLabel) IOException(java.io.IOException) JTablePersistenceManager(jmri.swing.JTablePersistenceManager) JTable(javax.swing.JTable) TransferHandler(javax.swing.TransferHandler) JSplitPane(javax.swing.JSplitPane)

Example 72 with JComponent

use of javax.swing.JComponent in project JMRI by JMRI.

the class Ds64TabbedPanel method changeGuiElementHighlight.

private void changeGuiElementHighlight(Integer reportedState, Integer reportedIndexToRead) {
    log.debug("changedGuiElementHiglight st=" + reportedState + " index=" + reportedIndexToRead);
    Color accessColor = Color.blue.brighter();
    Color noAccessColor = null;
    JComponent jc = null;
    if (reportedState == 33) {
        jc = whichComponent(reportedState, reportedIndexToRead);
        changeComponentBgColor(jc, accessColor);
    }
    if (reportedState == 48) {
        changeGuiElementUnHighlight(33, reportedIndexToRead);
        jc = whichComponent(49, reportedIndexToRead);
        if (jc != null) {
            changeComponentBgColor(jc, accessColor);
        }
    }
    if (reportedState == 64) {
        jc = whichComponent(49, reportedIndexToRead);
        changeComponentBgColor(jc, noAccessColor);
    }
}
Also used : Color(java.awt.Color) JComponent(javax.swing.JComponent)

Example 73 with JComponent

use of javax.swing.JComponent in project cytoscape-api by cytoscape.

the class LookAndFeelUtil method equalizeSize.

/**
	 * Resizes the given components making them equal in size.
	 */
public static void equalizeSize(final JComponent... components) {
    if (components == null || components.length == 0)
        return;
    final Dimension prefSize = components[0].getPreferredSize();
    final Dimension maxSize = components[0].getMaximumSize();
    for (JComponent c : components) {
        ensureSize(prefSize, c.getPreferredSize());
        ensureSize(maxSize, c.getMaximumSize());
    }
    for (JComponent c : components) {
        c.setPreferredSize(prefSize);
        c.setMaximumSize(maxSize);
    }
}
Also used : JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension)

Example 74 with JComponent

use of javax.swing.JComponent in project processdash by dtuma.

the class CustomColumnEditor method showWindow.

private CustomColumn showWindow(Component parent, boolean isAddOperation) {
    String title = resources.getString(isAddOperation ? "Add_Title" : "Edit_Title");
    JComponent fieldToFocus = isAddOperation ? columnID : columnName;
    while (true) {
        Object[] message = new Object[] { contents, new JOptionPaneTweaker.GrabFocus(fieldToFocus) };
        int userChoice = JOptionPane.showConfirmDialog(parent, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);
        if (userChoice != JOptionPane.OK_OPTION)
            return null;
        try {
            return buildColumn(isAddOperation);
        } catch (ColumnException ce) {
            JOptionPane.showMessageDialog(parent, ce.getMessage(), title, JOptionPane.ERROR_MESSAGE);
            if (ce.fieldToFocus != null)
                fieldToFocus = ce.fieldToFocus;
        }
    }
}
Also used : JComponent(javax.swing.JComponent)

Example 75 with JComponent

use of javax.swing.JComponent in project processdash by dtuma.

the class DefectImportForm method buildAndShowWindow.

private void buildAndShowWindow(Element xml, String windowName) {
    frame = new JFrame(windowName) {

        public void dispose() {
            super.dispose();
            disposeForm();
        }
    };
    DashboardIconFactory.setWindowIcon(frame);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    ((JComponent) getContainer()).setBorder(new EmptyBorder(5, 5, 5, 5));
    frame.getContentPane().add(BorderLayout.NORTH, getContainer());
    BoundDefectTable defectTable = new BoundDefectTable(this);
    defectTable.setBorder(new EmptyBorder(0, 10, 0, 10));
    frame.getContentPane().add(BorderLayout.CENTER, defectTable);
    frame.getContentPane().add(BorderLayout.SOUTH, createButtonBox());
    int width = XMLUtils.getXMLInt(xml, "windowWidth");
    if (width <= 0)
        width = 600;
    int height = XMLUtils.getXMLInt(xml, "windowHeight");
    if (height <= 0)
        height = 500;
    frame.setSize(width, height);
    frame.setVisible(true);
}
Also used : BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JComponent(javax.swing.JComponent) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

JComponent (javax.swing.JComponent)225 Component (java.awt.Component)44 JPanel (javax.swing.JPanel)37 JLabel (javax.swing.JLabel)34 JButton (javax.swing.JButton)28 BorderLayout (java.awt.BorderLayout)27 Dimension (java.awt.Dimension)23 Insets (java.awt.Insets)20 ActionEvent (java.awt.event.ActionEvent)16 ArrayList (java.util.ArrayList)16 ActionListener (java.awt.event.ActionListener)15 Color (java.awt.Color)13 GridBagConstraints (java.awt.GridBagConstraints)13 Point (java.awt.Point)13 GridBagLayout (java.awt.GridBagLayout)12 JScrollPane (javax.swing.JScrollPane)12 JTextField (javax.swing.JTextField)12 JFrame (javax.swing.JFrame)11 Container (java.awt.Container)8 FlowLayout (java.awt.FlowLayout)8