List of usage examples for javax.swing JButton getSize
public Dimension getSize()
From source file:fxts.stations.trader.ui.ABaseDialog.java
public void componentShown(ComponentEvent aEvent) { try {/*w ww . ja v a 2s. c o m*/ UserPreferences preferences = UserPreferences.getUserPreferences(TradeDesk.getInst().getUserName()); JButton button = getRootPane().getDefaultButton(); if (preferences.getBoolean("Mouse.snapDefaultButton") && button != null) { // snap mouse to middle of default button Robot robot = new Robot(); int x = (int) button.getLocationOnScreen().getX(); int y = (int) button.getLocationOnScreen().getY(); int width = (int) button.getSize().getWidth(); int height = (int) button.getSize().getHeight(); int x1 = x + width / 2; int y1 = y + height / 2; robot.mouseMove(x1, y1); } } catch (AWTException e) { e.printStackTrace(); } }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
public MirthTable(String prefix, Set<String> defaultVisibleColumns) { super();//from w ww . j a va 2s .c o m this.prefix = prefix; this.defaultVisibleColumns = defaultVisibleColumns; userPreferences = Preferences.userNodeForPackage(Mirth.class); columnOrderMap = new HashMap<String, Integer>(); if (StringUtils.isNotEmpty(prefix)) { try { userPreferences = Preferences.userNodeForPackage(Mirth.class); String columns = userPreferences.get(prefix + "ColumnOrderMap", ""); if (StringUtils.isNotEmpty(columns)) { columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns, Map.class); } } catch (Exception e) { } sortKeys = new ArrayList<SortKey>(); try { String sortOrder = userPreferences.get(prefix + "SortOrder", ""); if (StringUtils.isNotEmpty(sortOrder)) { sortKeys = ObjectXMLSerializer.getInstance().deserialize(sortOrder, List.class); } } catch (Exception e) { } } setDragEnabled(true); addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { boolean isAccelerated = (((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0) || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0)); if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) { PlatformUI.MIRTH_FRAME.doContextSensitiveSave(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); /* * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can * override it. */ putClientProperty("terminateEditOnFocusLost", Boolean.FALSE); getTableHeader().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { saveColumnOrder(); } }); final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon()); columnControlButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu columnMenu = getColumnMenu(); Dimension buttonSize = columnControlButton.getSize(); int xPos = columnControlButton.getComponentOrientation().isLeftToRight() ? buttonSize.width - columnMenu.getPreferredSize().width : 0; columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight()); } }); setColumnControl(columnControlButton); }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
public MirthTreeTable(String prefix, Set<String> defaultVisibleColumns) { customHiddenColumnMap = new HashMap<String, Set<String>>(); this.prefix = prefix; this.defaultVisibleColumns = defaultVisibleColumns; columnOrderMap = new HashMap<String, Integer>(); sortOrderColumn = -1;/*from w w w .j a v a2 s .co m*/ sortOrder = null; if (StringUtils.isNotEmpty(prefix)) { try { userPreferences = Preferences.userNodeForPackage(Mirth.class); String columns = userPreferences.get(prefix + "ColumnOrderMap", ""); if (StringUtils.isNotEmpty(columns)) { columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns, Map.class); } } catch (Exception e) { } try { String order = userPreferences.get(prefix + "SortOrder", ""); if (StringUtils.isNotEmpty(order)) { sortOrder = ObjectXMLSerializer.getInstance().deserialize(order, SortOrder.class); sortOrderColumn = userPreferences.getInt(prefix + "SortOrderColumn", -1); } } catch (Exception e) { } } addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { boolean isAccelerated = (((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0) || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0)); if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) { PlatformUI.MIRTH_FRAME.doContextSensitiveSave(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); /* * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can * override it. */ putClientProperty("terminateEditOnFocusLost", Boolean.FALSE); JTableHeader header = getTableHeader(); header.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { saveColumnOrder(); } }); header.setDefaultRenderer(new SortableHeaderCellRenderer(header.getDefaultRenderer())); final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon()); columnControlButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu columnMenu = getColumnMenu(); Dimension buttonSize = columnControlButton.getSize(); int xPos = columnControlButton.getComponentOrientation().isLeftToRight() ? buttonSize.width - columnMenu.getPreferredSize().width : 0; columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight()); } }); setColumnControl(columnControlButton); }
From source file:com.omertron.yamjtrakttv.view.MainWindow.java
private Dimension resizeWindow(JButton btn, int offsetX, int offsetY) { int width = btn.getSize().width + btn.getLocation().x + offsetX; int height = btn.getSize().height + btn.getLocation().y + offsetY; return new Dimension(width, height); }
From source file:fxts.stations.util.preferences.EditAction.java
public void actionPerformed(ActionEvent aEvent) { JButton okButton = UIManager.getInst().createButton(); JButton cancelButton = UIManager.getInst().createButton(); final JDialog dialog = new JDialog(mEditorPanel.getParentDialog()); dialog.setTitle(mEditorPanel.getTitle()); JPanel editPanel = new JPanel(); JPanel buttonPanel = new JPanel(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); //mainPanel.setLayout(new SideLayout()); //sets button panel buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); okButton.setText(mResMan.getString("IDS_OK_BUTTON")); //okButton.setPreferredSize(new Dimension(80, 27)); GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0;//from ww w .jav a 2 s. c om sideConstraints.gridy = 0; ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(okButton, sideConstraints); cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON")); //cancelButton.setPreferredSize(new Dimension(80, 27)); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 1; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(cancelButton, sideConstraints); //adds button panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0; sideConstraints.gridy = 1; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 1.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(buttonPanel, sideConstraints); //sets edit panel final IEditor editor = mType.getEditor(); editor.setValue(mValue); editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); Component editComp = editor.getComponent(); //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4. if (editComp instanceof FontChooser) { FontChooser fc = (FontChooser) editComp; fc.setNextFocusedComp(okButton); } editPanel.add(editComp, sideConstraints); //adds editor panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.gridx = 0; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(editPanel, sideConstraints); //adds main panel dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout()); //dialog.getContentPane().setLayout(new SideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.fill = GridBagConstraints.BOTH; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); dialog.getContentPane().add(mainPanel, sideConstraints); //adds listeners to buttons okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (editor.getValue().equals(mValue)) { // } else { mValue = editor.getValue(); mEditorPanel.setValue(mValue); mEditorPanel.refreshControls(); mEditorPanel.setValueChanged(true); } dialog.setVisible(false); dialog.dispose(); } }); okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitAction"); okButton.getActionMap().put("ExitAction", new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); okButton.requestFocus(); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); //dialog.setResizable(false); dialog.setModal(true); dialog.pack(); //sets minimal sizes for components Dimension dim = mainPanel.getSize(); mainPanel.setMinimumSize(dim); mainPanel.setPreferredSize(dim); //sets size of buttons Dimension dimOkButton = okButton.getSize(); Dimension dimCancelButton = cancelButton.getSize(); int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth() : (int) dimCancelButton.getWidth(); okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setVisible(true); }