List of usage examples for javax.swing JComponent validate
public void validate()
From source file:Main.java
public static void repaint(JComponent comp) { comp.validate(); comp.repaint(); }
From source file:Main.java
public static void printNow(int time, JComponent obj) { Dimension dim = obj.getSize(); obj.validate(); obj.paintImmediately(0, 0, dim.width, dim.height); try {//from w w w . ja va 2 s .c o m Thread.sleep(time); } catch (InterruptedException e) { } }
From source file:Main.java
/** * Repaints UI tree recursively.//from w ww . j ava 2 s . co m * * @param c UI component. */ private static void updateComponentTreeUI0(Component c) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; jc.invalidate(); jc.validate(); jc.repaint(); JPopupMenu jpm = jc.getComponentPopupMenu(); if (jpm != null && jpm.isVisible() && jpm.getInvoker() == jc) { updateComponentTreeUI(jpm); } } Component[] children = null; if (c instanceof JMenu) { children = ((JMenu) c).getMenuComponents(); } else if (c instanceof java.awt.Container) { children = ((java.awt.Container) c).getComponents(); } if (children != null) { for (int i = 0; i < children.length; i++) updateComponentTreeUI0(children[i]); } }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Deletes a Row in the table and there an data object * @param rowIndex the item to be deleted *//*from w w w . j a v a 2s. c om*/ protected void deleteRow(final int rowIndex) { FormDataObjIFace dObj = (FormDataObjIFace) dataObjList.get(rowIndex); if (dObj != null) { Object[] delBtnLabels = { getResourceString(addSearch ? "Remove" : "Delete"), getResourceString("CANCEL") }; int rv = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), UIRegistry.getLocalizedMessage(addSearch ? "ASK_REMOVE" : "ASK_DELETE", dObj.getIdentityTitle()), getResourceString(addSearch ? "Remove" : "Delete"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, delBtnLabels, delBtnLabels[1]); if (rv == JOptionPane.YES_OPTION) { boolean doOtherSide = true; DBTableInfo parentTblInfo = DBTableIdMgr.getInstance() .getByShortClassName(parentDataObj.getClass().getSimpleName()); if (parentTblInfo != null) { DBTableChildIFace ci = parentTblInfo.getItemByName(cellName); if (ci instanceof DBRelationshipInfo) { DBRelationshipInfo ri = (DBRelationshipInfo) ci; doOtherSide = ri.getType() == DBRelationshipInfo.RelationshipType.OneToMany; log.debug(ri.getType()); } } doOtherSide = false; parentDataObj.removeReference(dObj, dataSetFieldName, doOtherSide || addSearch); if (addSearch && mvParent != null && dObj.getId() != null) { mvParent.getTopLevel().addToBeSavedItem(dObj); } // 'addSearch' is used in FormViewObj, but here maybe we need to use 'doOtherSide' if (addSearch && mvParent != null && dObj.getId() != null) { mvParent.getTopLevel().addToBeSavedItem(dObj); } dataObjList.remove(rowIndex); model.fireDataChanged(); table.invalidate(); JComponent comp = mvParent.getTopLevel(); comp.validate(); comp.repaint(); reorderItems(rowIndex); tellMultiViewOfChange(); table.getSelectionModel().clearSelection(); updateUI(false); mvParent.getTopLevel().getCurrentValidator().setHasChanged(true); mvParent.getTopLevel().getCurrentValidator().validateForm(); mvParent.getCurrentValidator().setHasChanged(true); mvParent.getMultiViewParent().getCurrentValidator().validateForm(); if (!addSearch) { // Delete a child object by caching it in the Top Level MultiView if (mvParent != null && !mvParent.isTopLevel()) { mvParent.getTopLevel().addDeletedItem(dObj); String delMsg = (businessRules != null) ? businessRules.getDeleteMsg(dObj) : ""; UIRegistry.getStatusBar().setText(delMsg); } } } } }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Can create a new item or edit an existing it; or view and existing item. * @param rowIndex the index tho be editted * @param isEdit whether we are editing or view * @param isNew hwther the object is new *//*from w w w . j ava2 s . co m*/ @SuppressWarnings("unchecked") protected FormDataObjIFace editRow(final FormDataObjIFace dObjArg, final int rowIndex, final boolean isNew) { FormDataObjIFace dObj = dObjArg; // Add it in here so the Business Rules has a parent object to // get state from. if (!doSpecialAdd && parentDataObj != null && isEditing && isNew) { parentDataObj.addReference(dObj, dataSetFieldName); } /* XXX bug #9497: boolean editable = isEditing && (perm.canModify() || (perm.canAdd() && (isNew || isNewObj(dObj)))); final ViewBasedDisplayIFace dialog = FormHelper.createDataObjectDialog(mainComp, dObj, editable, isNew);*/ final ViewBasedDisplayIFace dialog = FormHelper.createDataObjectDialog(mainComp, dObj, isEditing, isNew); if (dialog != null) { // Now we need to get the MultiView and add it into the MV tree MultiView multiView = dialog.getMultiView(); // Note: The 'real' parent is the parent of the current MultiView // this is because the table's MultiView doesn't have a validator. MultiView realParent = mvParent.getMultiViewParent(); if (realParent != null) { realParent.addChildMV(multiView); } multiView.addCurrentValidator(); if (isNew && multiView.getCurrentViewAsFormViewObj() != null) { multiView.getCurrentViewAsFormViewObj().getBusinessRules().addChildrenToNewDataObjects(dObj); } dialog.setParentData(parentDataObj); DataProviderSessionIFace localSession = null; try { if (!isSkippingAttach) { if (dObj.getId() != null) { localSession = DataProviderFactory.getInstance().createSession(); //dObj = localSession.merge(dObj); localSession.attach(dObj); try { localSession.attach(dObj); } catch (org.hibernate.HibernateException ex) { String msg = ex.getMessage(); if (StringUtils.isNotEmpty(msg) && StringUtils.contains(msg, "dirty collection")) { //dObj = localSession.merge(dObj); } } } dialog.setSession(localSession); } if (isNew) { FormViewObj fvo = dialog.getMultiView().getCurrentViewAsFormViewObj(); if (fvo != null) { fvo.setCreatingNewObject(true); if (fvo.getBusinessRules() != null) { fvo.getBusinessRules().afterCreateNewObj(dObj); } } } dialog.setData(dObj); if (localSession != null) { localSession.close(); localSession = null; } dialog.setSession(null); dialog.createUI(); if (addSearch && includeAddBtn && isEditing && isNew) { dialog.setDoSave(true); dialog.getOkBtn().setText(UIRegistry.getResourceString("SAVE")); } dialog.showDisplay(true); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TableViewObj.class, ex); } finally { if (localSession != null) { localSession.close(); } } // OK, now unhook everything (MVs and the validators) multiView.removeCurrentValidator(); if (realParent != null) { realParent.removeChildMV(multiView); } if (isEditing) { if (dialog.getBtnPressed() == ViewBasedDisplayIFace.OK_BTN) { dialog.getMultiView().getDataFromUI(); if (mvParent != null) { tellMultiViewOfChange(); Object daObj = dialog.getMultiView().getCurrentViewAsFormViewObj() != null ? dialog.getMultiView().getCurrentViewAsFormViewObj().getCurrentDataObj() : null; if (daObj == null) { daObj = dialog.getMultiView().getData(); } dObj = daObj instanceof FormDataObjIFace ? (FormDataObjIFace) daObj : dObj; if (isNew) { if (daObj instanceof Orderable) { // They really should all be Orderable, // but just in case we check each one. int maxOrder = -1; for (Object obj : dataObjList) { if (obj instanceof Orderable) { maxOrder = Math.max(((Orderable) obj).getOrderIndex(), maxOrder); } } ((Orderable) daObj).setOrderIndex(maxOrder + 1); if (orderUpBtn == null) { addOrderablePanel(); } } dataObjList.add(daObj); if (dataObjList != null && dataObjList.size() > 0) { if (dataObjList.get(0) instanceof Comparable<?>) { Collections.sort((List) dataObjList); } } if (origDataSet != null) { origDataSet.add(daObj); } model.setValueAt(daObj, 0, dataObjList.size() - 1); } model.fireDataChanged(); table.invalidate(); table.repaint(); JComponent comp = mvParent.getTopLevel(); comp.validate(); comp.repaint(); } if (doSpecialAdd && parentDataObj != null && isEditing && isNew) { parentDataObj.addReference(dObj, dataSetFieldName); } } else if (dialog.isCancelled()) { // since it was added in before the dlg was shown we now need to remove. if (parentDataObj != null && isEditing && isNew) { parentDataObj.removeReference(dObj, dataSetFieldName); } if (mvParent.getMultiViewParent() != null) { if (mvParent.getMultiViewParent().getCurrentValidator() != null) { // rods 04/28/11 - it shouldn't turn on the save btn on Cancel //mvParent.getCurrentValidator().setHasChanged(true); mvParent.getMultiViewParent().getCurrentValidator().validateForm(); } multiView.getCurrentViewAsFormViewObj().doWasCacelled(); } } } dialog.dispose(); } else if (parentDataObj != null) { parentDataObj.removeReference(dObj, dataSetFieldName); } return dObj; }