public void mousePressed(MouseEvent e) { int x = e.getX(); if ((x >= (m_xpos - THUMB_WIDTH / 2)) && (x <= (m_xpos + THUMB_WIDTH)) && isPaintMargin()) { if (m_gc != null) { startDrag(); m_drag_x_diff = e.getX() - m_xpos; m_resize_indicator.setPosition(m_xpos); int col = m_gc.getColumn() + m_gc.getColumnSpan() - 1; GridView view = m_gc.getParentView(); FormSpecAdapter adapter = new FormSpecAdapter(view.getColumnSpec(col)); if (adapter.isComponentSize()) { m_units = TSUserPropertiesUtils.getString(UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS, "PX"); if (!FormUtils.isValidUnits(m_units)) m_units = "PX"; } else { m_units = adapter.getConstantUnits(); if (m_units == null) m_units = "PX"; } } } else { m_view.deselectAll(); m_form.setSelected(true); m_gc = null; } }
/** * Builds a list of components (Component) for a form that are ordered in the default focus order. */ public static LinkedHashSet buildDefaultFocusPolicy(FormComponent fc) { System.out.println("buildDefaultFocusPolicy form: " + fc.getId()); final FormComponent theform = fc; LinkedHashSet default_policy = new LinkedHashSet(); LayoutFocusTraversalPolicy policy = new LayoutFocusTraversalPolicy() { protected boolean accept(Component aComponent) { if (aComponent instanceof StandardComponent) { if (((StandardComponent) aComponent).getBeanDelegate() == null) return false; } if (aComponent == theform) return super.accept(aComponent); if (aComponent instanceof FormComponent) { if (((FormComponent) aComponent).isTopLevelForm()) return false; } if (aComponent instanceof JTabbedPane) return true; if (aComponent != null) { /** handle the case for embedded focus cycle roots such as JTabbedPane forms */ Container cc = aComponent.getParent(); while (cc != null && cc != theform) { if (cc instanceof FormContainerComponent) { return false; } cc = cc.getParent(); } } return super.accept(aComponent); } }; Component comp = policy.getFirstComponent(fc); Component last_comp = policy.getLastComponent(fc); while (true) { /** Don't add scroll pane in design mode since the scroll bars might not be visible */ if (FormUtils.isDesignMode()) { if (!(comp instanceof JScrollPane) && !(comp instanceof JScrollBar)) { default_policy.add(comp); } } else { default_policy.add(comp); } if (comp == last_comp) break; System.out.println("FormFocusManager.getComponentAfter: " + comp.getClass()); comp = policy.getComponentAfter(fc, comp); } return default_policy; }
public void mouseReleased(MouseEvent e) { if (m_dragging && m_gc != null) { if (m_comp_size > 0) { int col = m_gc.getColumn() + m_gc.getColumnSpan() - 1; GridView view = m_gc.getParentView(); ColumnSpec oldspec = view.getColumnSpec(col); FormEditor editor = FormEditor.getEditor(view); if (editor != null) { NewSizeAdapter adapter = new NewSizeAdapter(oldspec, m_comp_size, m_units); if (!adapter.isResizeGrow() && !adapter.isBoundedSize()) { String newspec = FormUtils.toEncodedString(adapter); EditColumnSpecCommand cmd = new EditColumnSpecCommand( view.getParentForm(), col, new ColumnSpec(newspec), oldspec); CommandUtils.invoke(cmd, editor); } else { String msg = null; if (adapter.isBoundedSize()) { msg = I18N.getLocalizedMessage( "The column size is set to bounded.\nYou must manually set the size in the column specification window."); } else if (adapter.isResizeGrow()) { msg = I18N.getLocalizedMessage( "The column resize behavior is set to grow.\nYou must manually set the size in the column specification window."); } else { msg = I18N.getLocalizedMessage( "You must manually set the size in the column specification window."); } String title = I18N.getLocalizedMessage("Error"); JOptionPane.showMessageDialog(m_view, msg, title, JOptionPane.ERROR_MESSAGE); } } else { assert (false); } } javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { m_overlay.setResizeIndicator(null); m_overlay.repaint(); m_dragging = false; update(m_gc); } }); } }