List of usage examples for javax.swing JLabel setOpaque
@BeanProperty(expert = true, description = "The component's opacity") public void setOpaque(boolean isOpaque)
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a new Text Field/*from ww w. j a v a2 s .c o m*/ * * @param container - parent container * @param name - name of text field * @param initialValue - initial value of text field * @param mnemonic - mnemonic key * @param tooltip - tool tip for field * @param suffix - suffix text for field * @param labelWidth - label width * @param placement - TableLayout placement * @param debug - turn on/off red debug borders * @return JTextField */ public static JTextField addTextField(Container container, String name, String initialValue, int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) { double[][] size = null; JPanel panel = new JPanel(); panel.setOpaque(false); if (suffix.equals("")) size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } }; else size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } }; TableLayout layout = new TableLayout(size); panel.setLayout(layout); JLabel label = new JLabel(name); label.setDisplayedMnemonic(mnemonic); JTextField result = new JTextField(20); label.setLabelFor(result); label.setOpaque(false); result.setToolTipText(tooltip); if (initialValue != null) result.setText(initialValue); panel.add(label, "0, 0, r, c"); panel.add(result, "1, 0, f, c"); if (suffix.length() != 0) { JLabel suffixLabel = new JLabel(" " + suffix); panel.add(suffixLabel, "2,0, l, c"); } if (debug == true) panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), panel.getBorder())); container.add(panel, placement); return result; }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a new Password Text Field/* ww w. j a v a2 s .co m*/ * * @param container - parent container * @param name - name of text field * @param initialValue - initial value of text field * @param mnemonic - mnemonic key * @param tooltip - tool tip for field * @param suffix - suffix text for field * @param labelWidth - label width * @param placement - TableLayout placement * @param debug - turn on/off red debug borders * @return JPasswordField */ public static JPasswordField addPasswordField(Container container, String name, String initialValue, int mnemonic, String tooltip, String suffix, double labelWidth, String placement, boolean debug) { double[][] size = null; JPanel panel = new JPanel(); panel.setOpaque(false); if (suffix.equals("")) size = new double[][] { { labelWidth, TableLayout.FILL }, { 30 } }; else size = new double[][] { { labelWidth, TableLayout.FILL, TableLayout.PREFERRED }, { 30 } }; TableLayout layout = new TableLayout(size); panel.setLayout(layout); JLabel label = new JLabel(name); label.setDisplayedMnemonic(mnemonic); JPasswordField result = new JPasswordField(20); label.setLabelFor(result); label.setOpaque(false); result.setToolTipText(tooltip); if (initialValue != null) result.setText(initialValue); panel.add(label, "0, 0, r, c"); panel.add(result, "1, 0, f, c"); if (suffix.length() != 0) { JLabel suffixLabel = new JLabel(" " + suffix); panel.add(suffixLabel, "2,0, l, c"); } if (debug == true) panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), panel.getBorder())); container.add(panel, placement); return result; }
From source file:ome.formats.importer.gui.GuiCommonElements.java
/** * Add a TextArea that has scrolling functionality * //from ww w .j a va 2s . com * @param container - parent container * @param name - name of text area * @param text - text to put in text area * @param mnemonic - mnemonic key * @param placement - TableLayout placement in parent container * @param debug - turn on/off red debug borders * @return JTextArea */ public static JTextArea addScrollingTextArea(Container container, String name, String text, int mnemonic, String placement, boolean debug) { JPanel panel = new JPanel(); panel.setOpaque(false); double size[][] = { { TableLayout.FILL }, { 20, TableLayout.FILL } }; TableLayout layout = new TableLayout(size); panel.setLayout(layout); JTextArea textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setOpaque(true); JScrollPane areaScrollPane = new JScrollPane(textArea); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); if (debug == true) panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), panel.getBorder())); if (!name.equals("")) { JLabel label = new JLabel(name); label.setOpaque(false); label.setDisplayedMnemonic(mnemonic); panel.add(label, "0, 0, l, c"); panel.add(areaScrollPane, "0, 1, f, f"); } else { panel.add(areaScrollPane, "0, 0, 0, 1"); } container.add(panel, placement); return textArea; }
From source file:op.care.bhp.PnlBHP.java
private CollapsiblePane createCP4(final BHP bhp) { final CollapsiblePane bhpPane = new CollapsiblePane(); bhpPane.setCollapseOnTitleClick(false); ActionListener applyActionListener = new ActionListener() { @Override//from w w w .ja v a2s .c o m public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (bhp.getPrescription().isClosed()) { return; } if (BHPTools.isChangeable(bhp)) { outcomeText = null; if (bhp.getNeedsText()) { new DlgYesNo(SYSConst.icon48comment, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { outcomeText = null; } else { outcomeText = o.toString(); } } }, "nursingrecords.bhp.describe.outcome", null, null); } if (bhp.getNeedsText() && outcomeText == null) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage("nursingrecords.bhp.notext.nooutcome", DisplayMessage.WARNING)); return; } if (bhp.getPrescription().isWeightControlled()) { new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { weight = null; } else { weight = (BigDecimal) o; } } }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() { @Override public boolean isValid(String value) { BigDecimal bd = parse(value); return bd != null && bd.compareTo(BigDecimal.ZERO) > 0; } @Override public BigDecimal parse(String text) { return SYSTools.parseDecimal(text); } }); } if (bhp.getPrescription().isWeightControlled() && weight == null) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage( "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING)); return; } EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); if (myBHP.isOnDemand()) { em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC_FORCE_INCREMENT); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC_FORCE_INCREMENT); } else { em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); } myBHP.setState(BHPTools.STATE_DONE); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); myBHP.setText(outcomeText); Prescription involvedPresciption = null; if (myBHP.shouldBeCalculated()) { MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()); MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(), weight, myBHP); // Was the prescription closed during this withdraw ? involvedPresciption = em.find(Prescription.class, myBHP.getPrescription().getID()); } BHP outcomeBHP = null; // add outcome check BHP if necessary if (!myBHP.isOutcomeText() && myBHP.getPrescriptionSchedule().getCheckAfterHours() != null) { outcomeBHP = em.merge(new BHP(myBHP)); mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND).add(outcomeBHP); } em.getTransaction().commit(); if (myBHP.shouldBeCalculated() && involvedPresciption.isClosed()) { // && reload(); } else if (outcomeBHP != null) { reload(); } else { mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(myBHP.getShift()).remove(position); mapShift2BHP.get(myBHP.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { // This whole thing here is only to handle the BPHs on Demand // Fix the other BHPs on demand. If not, you will get locking exceptions, // we FORCED INCREMENTED LOCKS on the Schedule and the Prescription. ArrayList<BHP> changeList = new ArrayList<BHP>(); for (BHP bhp : mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)) { if (bhp.getPrescription().getID() == myBHP.getPrescription().getID() && bhp.getBHPid() != myBHP.getBHPid()) { bhp.setPrescription(myBHP.getPrescription()); bhp.setPrescriptionSchedule(myBHP.getPrescriptionSchedule()); changeList.add(bhp); } } for (BHP bhp : changeList) { mapBHP2Pane.put(bhp, createCP4(myBHP)); position = mapShift2BHP.get(bhp.getShift()).indexOf(bhp); mapShift2BHP.get(myBHP.getShift()).remove(position); mapShift2BHP.get(myBHP.getShift()).add(position, bhp); } Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (RollbackException ole) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }; // JPanel titlePanelleft = new JPanel(); // titlePanelleft.setLayout(new BoxLayout(titlePanelleft, BoxLayout.LINE_AXIS)); MedStock stock = mapPrescription2Stock.get(bhp.getPrescription()); if (bhp.hasMed() && stock == null) { stock = MedStockTools .getStockInUse(TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm())); mapPrescription2Stock.put(bhp.getPrescription(), stock); } String title; if (bhp.isOutcomeText()) { title = "<html><font size=+1>" + SYSConst.html_italic(SYSTools .left("“" + PrescriptionTools.getShortDescriptionAsCompactText( bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH) + BHPTools.getScheduleText(bhp.getOutcome4(), "”, ", "")) + " [" + bhp.getPrescriptionSchedule().getCheckAfterHours() + " " + SYSTools.xx("misc.msg.Hour(s)") + "] " + BHPTools.getScheduleText(bhp, ", ", "") + (bhp.getPrescription().isWeightControlled() ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? "" : (bhp.getStockTransaction().isEmpty() ? " " : NumberFormat.getNumberInstance() .format(bhp.getStockTransaction().get(0).getWeight()) + "g ")) : "") + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>" : "") + "</font></html>"; } else { title = "<html><font size=+1>" + SYSTools.left(PrescriptionTools.getShortDescriptionAsCompactText( bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH) + (bhp.hasMed() ? ", <b>" + SYSTools.getAsHTML(bhp.getDose()) + " " + DosageFormTools.getUsageText( bhp.getPrescription().getTradeForm().getDosageForm()) + "</b>" : "") + BHPTools.getScheduleText(bhp, ", ", "") + (bhp.getPrescription().isWeightControlled() ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? "" : (bhp.getStockTransaction().isEmpty() ? " " : NumberFormat.getNumberInstance() .format(bhp.getStockTransaction().get(0).getWeight()) + "g ")) : "") + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>" : "") + "</font></html>"; } DefaultCPTitle cptitle = new DefaultCPTitle(title, OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener : null); JLabel icon1 = new JLabel(BHPTools.getIcon(bhp)); icon1.setOpaque(false); if (!bhp.isOpen()) { icon1.setToolTipText(DateFormat.getDateTimeInstance().format(bhp.getIst())); } JLabel icon2 = new JLabel(BHPTools.getWarningIcon(bhp, stock)); icon2.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon1); cptitle.getAdditionalIconPanel().add(icon2); if (bhp.getPrescription().isClosed()) { JLabel icon3 = new JLabel(SYSConst.icon22stopSign); icon3.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon3); } if (bhp.isOutcomeText()) { JLabel icon4 = new JLabel(SYSConst.icon22comment); icon4.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon4); } if (!bhp.isOutcomeText() && bhp.getPrescriptionSchedule().getCheckAfterHours() != null) { JLabel icon4 = new JLabel(SYSConst.icon22intervalBySecond); icon4.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon4); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { if (!bhp.getPrescription().isClosed()) { /*** * _ _ _ _ * | |__ | |_ _ __ / \ _ __ _ __ | |_ _ * | '_ \| __| '_ \ / _ \ | '_ \| '_ \| | | | | * | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| | * |_.__/ \__|_| |_/_/ \_\ .__/| .__/|_|\__, | * |_| |_| |___/ */ JButton btnApply = new JButton(SYSConst.icon22apply); btnApply.setPressedIcon(SYSConst.icon22applyPressed); btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT); btnApply.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnApply.tooltip")); btnApply.addActionListener(applyActionListener); btnApply.setContentAreaFilled(false); btnApply.setBorder(null); btnApply.setEnabled(bhp.isOpen() && (!bhp.hasMed() || mapPrescription2Stock.containsKey(bhp.getPrescription()))); cptitle.getRight().add(btnApply); /*** * ____ _ _ * ___ _ __ ___ _ __ / ___|| |_ ___ ___| | __ * / _ \| '_ \ / _ \ '_ \\___ \| __/ _ \ / __| |/ / * | (_) | |_) | __/ | | |___) | || (_) | (__| < * \___/| .__/ \___|_| |_|____/ \__\___/ \___|_|\_\ * |_| */ if (bhp.hasMed() && stock == null && MedInventoryTools.getNextToOpen( TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm())) != null) { final JButton btnOpenStock = new JButton(SYSConst.icon22ledGreenOn); btnOpenStock.setPressedIcon(SYSConst.icon22ledGreenOff); btnOpenStock.setAlignmentX(Component.RIGHT_ALIGNMENT); btnOpenStock.setContentAreaFilled(false); btnOpenStock.setBorder(null); btnOpenStock.setToolTipText(SYSTools .toHTMLForScreen(SYSTools.xx("nursingrecords.inventory.stock.btnopen.tooltip"))); btnOpenStock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); MedStock myStock = em.merge(MedInventoryTools.openNext( TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()))); em.lock(myStock, LockModeType.OPTIMISTIC); em.getTransaction().commit(); OPDE.getDisplayManager() .addSubMessage(new DisplayMessage( String.format(SYSTools.xx("newstocks.stock.has.been.opened"), myStock.getID().toString()))); reload(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); cptitle.getRight().add(btnOpenStock); } if (!bhp.isOutcomeText()) { /*** * _ _ ____ __ * | |__ | |_ _ __ | _ \ ___ / _|_ _ ___ ___ * | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \ * | |_) | |_| | | | _ < __/ _| |_| \__ \ __/ * |_.__/ \__|_| |_|_| \_\___|_| \__,_|___/\___| * */ final JButton btnRefuse = new JButton(SYSConst.icon22cancel); btnRefuse.setPressedIcon(SYSConst.icon22cancelPressed); btnRefuse.setAlignmentX(Component.RIGHT_ALIGNMENT); btnRefuse.setContentAreaFilled(false); btnRefuse.setBorder(null); btnRefuse.setToolTipText( SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuse.tooltip"))); btnRefuse.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (BHPTools.isChangeable(bhp)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); myBHP.setState(BHPTools.STATE_REFUSED); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } em.getTransaction().commit(); mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnRefuse.setEnabled(!bhp.isOnDemand() && bhp.isOpen()); cptitle.getRight().add(btnRefuse); /*** * _ _ ____ __ ____ _ _ * | |__ | |_ _ __ | _ \ ___ / _|_ _ ___ ___| _ \(_)___ ___ __ _ _ __ __| | * | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \ | | | / __|/ __/ _` | '__/ _` | * | |_) | |_| | | | _ < __/ _| |_| \__ \ __/ |_| | \__ \ (_| (_| | | | (_| | * |_.__/ \__|_| |_|_| \_\___|_| \__,_|___/\___|____/|_|___/\___\__,_|_| \__,_| * */ final JButton btnRefuseDiscard = new JButton(SYSConst.icon22deleteall); btnRefuseDiscard.setPressedIcon(SYSConst.icon22deleteallPressed); btnRefuseDiscard.setAlignmentX(Component.RIGHT_ALIGNMENT); btnRefuseDiscard.setContentAreaFilled(false); btnRefuseDiscard.setBorder(null); btnRefuseDiscard.setToolTipText( SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuseDiscard.tooltip"))); btnRefuseDiscard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() != BHPTools.STATE_OPEN) { return; } if (BHPTools.isChangeable(bhp)) { if (bhp.getPrescription().isWeightControlled()) { new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (SYSTools.catchNull(o).isEmpty()) { weight = null; } else { weight = (BigDecimal) o; } } }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() { @Override public boolean isValid(String value) { BigDecimal bd = parse(value); return bd != null && bd.compareTo(BigDecimal.ZERO) > 0; } @Override public BigDecimal parse(String text) { return SYSTools.parseDecimal(text); } }); } if (bhp.getPrescription().isWeightControlled() && weight == null) { OPDE.getDisplayManager().addSubMessage(new DisplayMessage( "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING)); return; } EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); myBHP.setState(BHPTools.STATE_REFUSED_DISCARDED); myBHP.setUser(em.merge(OPDE.getLogin().getUser())); myBHP.setIst(new Date()); myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myBHP.setMDate(new Date()); if (myBHP.shouldBeCalculated()) { MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm()); if (inventory != null) { MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(), weight, myBHP); } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage("nursingrecords.bhp.NoInventory")); } } mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } em.getTransaction().commit(); mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnRefuseDiscard.setEnabled( !bhp.isOnDemand() && bhp.hasMed() && bhp.shouldBeCalculated() && bhp.isOpen()); cptitle.getRight().add(btnRefuseDiscard); } /*** * _ _ _____ _ * | |__ | |_ _ __ | ____|_ __ ___ _ __ | |_ _ _ * | '_ \| __| '_ \| _| | '_ ` _ \| '_ \| __| | | | * | |_) | |_| | | | |___| | | | | | |_) | |_| |_| | * |_.__/ \__|_| |_|_____|_| |_| |_| .__/ \__|\__, | * |_| |___/ */ final JButton btnEmpty = new JButton(SYSConst.icon22empty); btnEmpty.setPressedIcon(SYSConst.icon22emptyPressed); btnEmpty.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEmpty.setContentAreaFilled(false); btnEmpty.setBorder(null); btnEmpty.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnEmpty.tooltip")); btnEmpty.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (bhp.getState() == BHPTools.STATE_OPEN) { return; } BHP outcomeBHP = BHPTools.getComment(bhp); if (outcomeBHP != null && !outcomeBHP.isOpen()) { // already commented return; } if (BHPTools.isChangeable(bhp)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); BHP myBHP = em.merge(bhp); em.lock(myBHP, LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC); em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC); // the normal BHPs (those assigned to a NursingProcess) are reset to the OPEN state. // TXs are deleted myBHP.setState(BHPTools.STATE_OPEN); myBHP.setUser(null); myBHP.setIst(null); myBHP.setiZeit(null); myBHP.setMDate(new Date()); myBHP.setText(null); if (myBHP.shouldBeCalculated()) { for (MedStockTransaction tx : myBHP.getStockTransaction()) { em.remove(tx); } myBHP.getStockTransaction().clear(); } if (outcomeBHP != null) { BHP myOutcomeBHP = em.merge(outcomeBHP); em.remove(myOutcomeBHP); } if (myBHP.isOnDemand()) { em.remove(myBHP); } em.getTransaction().commit(); if (myBHP.isOnDemand()) { reload(); } else { mapBHP2Pane.put(myBHP, createCP4(myBHP)); int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp); mapShift2BHP.get(bhp.getShift()).remove(position); mapShift2BHP.get(bhp.getShift()).add(position, myBHP); if (myBHP.isOnDemand()) { Collections.sort(mapShift2BHP.get(myBHP.getShift()), BHPTools.getOnDemandComparator()); } else { Collections.sort(mapShift2BHP.get(myBHP.getShift())); } mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift())); buildPanel(false); } } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("nursingrecords.bhp.notchangeable"))); } } }); btnEmpty.setEnabled(!bhp.isOpen()); cptitle.getRight().add(btnEmpty); } /*** * _ _ ___ __ * | |__ | |_ _ __ |_ _|_ __ / _| ___ * | '_ \| __| '_ \ | || '_ \| |_ / _ \ * | |_) | |_| | | || || | | | _| (_) | * |_.__/ \__|_| |_|___|_| |_|_| \___/ * */ final JButton btnInfo = new JButton(SYSConst.icon22info); btnInfo.setPressedIcon(SYSConst.icon22infoPressed); btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT); btnInfo.setContentAreaFilled(false); btnInfo.setBorder(null); btnInfo.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnInfo.tooltip")); final JTextPane txt = new JTextPane(); txt.setContentType("text/html"); txt.setEditable(false); final JidePopup popupInfo = new JidePopup(); popupInfo.setMovable(false); popupInfo.setContentPane(new JScrollPane(txt)); popupInfo.removeExcludedComponent(txt); popupInfo.setDefaultFocusComponent(txt); btnInfo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { popupInfo.setOwner(btnInfo); if (bhp.isOutcomeText() && !bhp.isOpen()) { txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getText()))); } else { txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText()))); } // txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText()))); GUITools.showPopup(popupInfo, SwingConstants.SOUTH_WEST); } }); if (bhp.isOutcomeText() && !bhp.isOpen()) { btnInfo.setEnabled(true); } else { btnInfo.setEnabled(!SYSTools.catchNull(bhp.getPrescription().getText()).isEmpty()); } cptitle.getRight().add(btnInfo); } bhpPane.setTitleLabelComponent(cptitle.getMain()); bhpPane.setSlidingDirection(SwingConstants.SOUTH); final JTextPane contentPane = new JTextPane(); contentPane.setEditable(false); contentPane.setContentType("text/html"); bhpPane.setContentPane(contentPane); bhpPane.setBackground(bhp.getBG()); bhpPane.setForeground(bhp.getFG()); try { bhpPane.setCollapsed(true); } catch (PropertyVetoException e) { OPDE.error(e); } bhpPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { contentPane.setText(SYSTools.toHTML( PrescriptionTools.getPrescriptionAsHTML(bhp.getPrescription(), false, false, true, false))); } }); bhpPane.setHorizontalAlignment(SwingConstants.LEADING); bhpPane.setOpaque(false); return bhpPane; }
From source file:op.care.dfn.PnlDFN.java
private CollapsiblePane createCP4(final DFN dfn) { final CollapsiblePane dfnPane = new CollapsiblePane(); ActionListener applyActionListener = new ActionListener() { @Override/*from w ww .j a v a2 s. c o m*/ public void actionPerformed(ActionEvent actionEvent) { if (dfn.getState() == DFNTools.STATE_DONE) { return; } if (!dfn.isOnDemand() && dfn.getNursingProcess().isClosed()) { return; } if (DFNTools.isChangeable(dfn)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); DFN myDFN = em.merge(dfn); em.lock(myDFN, LockModeType.OPTIMISTIC); if (!myDFN.isOnDemand()) { em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC); } myDFN.setState(DFNTools.STATE_DONE); myDFN.setUser(em.merge(OPDE.getLogin().getUser())); myDFN.setIst(new Date()); myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myDFN.setMdate(new Date()); em.getTransaction().commit(); CollapsiblePane cp1 = createCP4(myDFN); synchronized (mapDFN2Pane) { mapDFN2Pane.put(myDFN, cp1); } synchronized (mapShift2DFN) { int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN); mapShift2DFN.get(myDFN.getShift()).remove(position); mapShift2DFN.get(myDFN.getShift()).add(position, myDFN); } CollapsiblePane cp2 = createCP4(myDFN.getShift()); synchronized (mapShift2Pane) { mapShift2Pane.put(myDFN.getShift(), cp2); } buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable"))); } } }; String title = "<html><font size=+1>" + // (dfn.isFloating() ? (dfn.isActive() ? "(!) " : "(OK) ") : "") + SYSTools.left(dfn.getIntervention().getBezeichnung(), MAX_TEXT_LENGTH) + DFNTools.getScheduleText(dfn, " [", "]") + ", " + dfn.getMinutes() + " " + SYSTools.xx("misc.msg.Minute(s)") + (dfn.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(dfn.getUser().getUID()) + "</i>" : "") + "</font></html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener : null); dfnPane.setCollapseOnTitleClick(false); // cptitle.getTitleButton().setIcon(DFNTools.getIcon(dfn)); JLabel icon1 = new JLabel(DFNTools.getIcon(dfn)); icon1.setOpaque(false); JLabel icon2 = new JLabel(DFNTools.getFloatingIcon(dfn)); icon2.setOpaque(false); cptitle.getAdditionalIconPanel().add(icon1); cptitle.getAdditionalIconPanel().add(icon2); if (dfn.isFloating()) { cptitle.getButton().setToolTipText(SYSTools.xx("nursingrecords.dfn.enforced.tooltip") + ": " + DateFormat.getDateInstance().format(dfn.getStDatum())); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) && (dfn.isOnDemand() || !dfn.getNursingProcess().isClosed())) { /*** * _ _ _ _ * | |__ | |_ _ __ / \ _ __ _ __ | |_ _ * | '_ \| __| '_ \ / _ \ | '_ \| '_ \| | | | | * | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| | * |_.__/ \__|_| |_/_/ \_\ .__/| .__/|_|\__, | * |_| |_| |___/ */ JButton btnApply = new JButton(SYSConst.icon22apply); btnApply.setPressedIcon(SYSConst.icon22applyPressed); btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT); btnApply.setContentAreaFilled(false); btnApply.setBorder(null); btnApply.addActionListener(applyActionListener); btnApply.setEnabled(!dfn.isOnDemand() && dfn.isOpen()); cptitle.getRight().add(btnApply); // JPanel spacer = new JPanel(); // spacer.setOpaque(false); // cptitle.getRight().add(spacer); /*** * _ _ ____ _ * | |__ | |_ _ __ / ___|__ _ _ __ ___ ___| | * | '_ \| __| '_ \| | / _` | '_ \ / __/ _ \ | * | |_) | |_| | | | |__| (_| | | | | (_| __/ | * |_.__/ \__|_| |_|\____\__,_|_| |_|\___\___|_| * */ final JButton btnCancel = new JButton(SYSConst.icon22cancel); btnCancel.setPressedIcon(SYSConst.icon22cancelPressed); btnCancel.setAlignmentX(Component.RIGHT_ALIGNMENT); btnCancel.setContentAreaFilled(false); btnCancel.setBorder(null); // btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip")); btnCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (dfn.getState() == DFNTools.STATE_REFUSED) { return; } if (DFNTools.isChangeable(dfn)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); DFN myDFN = em.merge(dfn); em.lock(myDFN, LockModeType.OPTIMISTIC); if (!myDFN.isOnDemand()) { em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC); } myDFN.setState(DFNTools.STATE_REFUSED); myDFN.setUser(em.merge(OPDE.getLogin().getUser())); myDFN.setIst(new Date()); myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date())); myDFN.setMdate(new Date()); em.getTransaction().commit(); CollapsiblePane cp1 = createCP4(myDFN); synchronized (mapDFN2Pane) { mapDFN2Pane.put(myDFN, cp1); } synchronized (mapShift2DFN) { int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN); mapShift2DFN.get(myDFN.getShift()).remove(position); mapShift2DFN.get(myDFN.getShift()).add(position, myDFN); } CollapsiblePane cp2 = createCP4(myDFN.getShift()); synchronized (mapShift2Pane) { mapShift2Pane.put(myDFN.getShift(), cp2); } buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable"))); } } }); btnCancel.setEnabled(!dfn.isOnDemand() && dfn.isOpen()); cptitle.getRight().add(btnCancel); /*** * _ _ _____ _ * | |__ | |_ _ __ | ____|_ __ ___ _ __ | |_ _ _ * | '_ \| __| '_ \| _| | '_ ` _ \| '_ \| __| | | | * | |_) | |_| | | | |___| | | | | | |_) | |_| |_| | * |_.__/ \__|_| |_|_____|_| |_| |_| .__/ \__|\__, | * |_| |___/ */ final JButton btnEmpty = new JButton(SYSConst.icon22empty); btnEmpty.setPressedIcon(SYSConst.icon22emptyPressed); btnEmpty.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEmpty.setContentAreaFilled(false); btnEmpty.setBorder(null); // btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip")); btnEmpty.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (dfn.getState() == DFNTools.STATE_OPEN) { return; } if (DFNTools.isChangeable(dfn)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); DFN myDFN = em.merge(dfn); em.lock(myDFN, LockModeType.OPTIMISTIC); if (!myDFN.isOnDemand()) { em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC); } // on demand DFNs are deleted if they not wanted anymore if (myDFN.isOnDemand()) { em.remove(myDFN); synchronized (mapDFN2Pane) { mapDFN2Pane.remove(myDFN); } synchronized (mapShift2DFN) { mapShift2DFN.get(myDFN.getShift()).remove(myDFN); } } else { // the normal DFNs (those assigned to a NursingProcess) are reset to the OPEN state. myDFN.setState(DFNTools.STATE_OPEN); myDFN.setUser(null); myDFN.setIst(null); myDFN.setiZeit(null); myDFN.setMdate(new Date()); CollapsiblePane cp1 = createCP4(myDFN); synchronized (mapDFN2Pane) { mapDFN2Pane.put(myDFN, cp1); } synchronized (mapShift2DFN) { int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN); mapShift2DFN.get(myDFN.getShift()).remove(position); mapShift2DFN.get(myDFN.getShift()).add(position, myDFN); } } em.getTransaction().commit(); CollapsiblePane cp2 = createCP4(myDFN.getShift()); synchronized (mapShift2Pane) { mapShift2Pane.put(myDFN.getShift(), cp2); } buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } else { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable"))); } } }); btnEmpty.setEnabled(!dfn.isOpen()); cptitle.getRight().add(btnEmpty); /*** * _ _ __ __ _ _ * | |__ | |_ _ __ | \/ (_)_ __ _ _| |_ ___ ___ * | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __| * | |_) | |_| | | | | | | | | | | |_| | || __/\__ \ * |_.__/ \__|_| |_|_| |_|_|_| |_|\__,_|\__\___||___/ * */ final JButton btnMinutes = new JButton(SYSConst.icon22clock); btnMinutes.setPressedIcon(SYSConst.icon22clockPressed); btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMinutes.setContentAreaFilled(false); btnMinutes.setBorder(null); // btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip")); btnMinutes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (!DFNTools.isChangeable(dfn)) { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable"))); return; } final JPopupMenu menu = SYSCalendar.getMinutesMenu( new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); DFN myDFN = em.merge(dfn); em.lock(myDFN, LockModeType.OPTIMISTIC); if (!myDFN.isOnDemand()) { em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC); } myDFN.setMinutes(new BigDecimal((Integer) o)); myDFN.setUser(em.merge(OPDE.getLogin().getUser())); myDFN.setMdate(new Date()); em.getTransaction().commit(); CollapsiblePane cp1 = createCP4(myDFN); synchronized (mapDFN2Pane) { mapDFN2Pane.put(myDFN, cp1); } synchronized (mapShift2DFN) { int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN); mapShift2DFN.get(myDFN.getShift()).remove(position); mapShift2DFN.get(myDFN.getShift()).add(position, myDFN); } CollapsiblePane cp2 = createCP4(myDFN.getShift()); synchronized (mapShift2Pane) { mapShift2Pane.put(myDFN.getShift(), cp2); } buildPanel(false); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); menu.show(btnMinutes, 0, btnMinutes.getHeight()); } }); btnMinutes.setEnabled(dfn.getState() != DFNTools.STATE_OPEN); cptitle.getRight().add(btnMinutes); } /*** * _ _ ___ __ * | |__ | |_ _ __ |_ _|_ __ / _| ___ * | '_ \| __| '_ \ | || '_ \| |_ / _ \ * | |_) | |_| | | || || | | | _| (_) | * |_.__/ \__|_| |_|___|_| |_|_| \___/ * */ final JButton btnInfo = new JButton(SYSConst.icon22info); final JidePopup popupInfo = new JidePopup(); btnInfo.setPressedIcon(SYSConst.icon22infoPressed); btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT); btnInfo.setContentAreaFilled(false); btnInfo.setBorder(null); final JTextPane txt = new JTextPane(); txt.setContentType("text/html"); txt.setEditable(false); popupInfo.setMovable(false); popupInfo.getContentPane().setLayout(new BoxLayout(popupInfo.getContentPane(), BoxLayout.LINE_AXIS)); popupInfo.getContentPane().add(new JScrollPane(txt)); popupInfo.removeExcludedComponent(txt); popupInfo.setDefaultFocusComponent(txt); btnInfo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { popupInfo.setOwner(btnInfo); txt.setText(SYSTools.toHTML(SYSConst.html_div(dfn.getInterventionSchedule().getBemerkung()))); GUITools.showPopup(popupInfo, SwingConstants.WEST); } }); btnInfo.setEnabled( !dfn.isOnDemand() && !SYSTools.catchNull(dfn.getInterventionSchedule().getBemerkung()).isEmpty()); cptitle.getRight().add(btnInfo); dfnPane.setTitleLabelComponent(cptitle.getMain()); dfnPane.setBackground(dfn.getBG()); dfnPane.setForeground(dfn.getFG()); try { dfnPane.setCollapsed(true); } catch (PropertyVetoException e) { OPDE.error(e); } dfnPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { JTextPane contentPane = new JTextPane(); contentPane.setContentType("text/html"); contentPane.setEditable(false); contentPane.setText(SYSTools .toHTML(NursingProcessTools.getAsHTML(dfn.getNursingProcess(), false, true, false, false))); dfnPane.setContentPane(contentPane); } }); dfnPane.setCollapsible(dfn.getNursingProcess() != null); dfnPane.setHorizontalAlignment(SwingConstants.LEADING); dfnPane.setOpaque(false); return dfnPane; }
From source file:org.datacleaner.widgets.table.DCTableCellRenderer.java
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { logger.debug("getTableCellRendererComponent({},{})", row, column); if (value != null) { if (value.getClass().isArray()) { // arrays are printed nicely this way value = ArrayUtils.toString(value); }//from w w w. j av a2s . c o m } // icons are displayed as labels if (value instanceof Icon) { final JLabel label = new JLabel((Icon) value); label.setOpaque(true); value = label; } final Component result; // render components directly if (value instanceof JComponent) { final JComponent component = (JComponent) value; component.setOpaque(true); if (component.getMouseListeners().length == 0) { component.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { MouseEvent newEvent = SwingUtilities.convertMouseEvent(component, e, _table); _table.consumeMouseClick(newEvent); } }); } result = component; } else { result = _delegate.getTableCellRendererComponent(_table, value, isSelected, hasFocus, row, column); assert result instanceof JLabel; } // alignment is applied to all labels or panels (with flowlayout) Alignment alignment = _alignmentOverrides.get(column); if (alignment == null) { alignment = Alignment.LEFT; } // set alignment if (value instanceof JPanel) { final LayoutManager layout = ((JPanel) value).getLayout(); if (layout instanceof FlowLayout) { final FlowLayout flowLayout = (FlowLayout) layout; flowLayout.setAlignment(alignment.getFlowLayoutAlignment()); } } else if (result instanceof JLabel) { final JLabel label = (JLabel) result; label.setHorizontalAlignment(alignment.getSwingContstantsAlignment()); WidgetUtils.setAppropriateFont(label); } return result; }
From source file:org.interreg.docexplore.ServerConfigPanel.java
public ServerConfigPanel(final File config, final File serverDir) throws Exception { super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); this.serverDir = serverDir; this.books = new Vector<Book>(); this.bookList = new JList(new DefaultListModel()); JPanel listPanel = new JPanel(new BorderLayout()); listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel"))); bookList.setOpaque(false);//w ww .ja va 2 s.co m bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bookList.setCellRenderer(new ListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Book book = (Book) value; JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>"); label.setOpaque(true); if (isSelected) { label.setBackground(TextToolbar.styleHighLightedBackground); label.setForeground(Color.white); } if (book.deleted) label.setForeground(Color.red); else if (!book.used) label.setForeground(Color.gray); return label; } }); bookList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; setFields((Book) bookList.getSelectedValue()); } }); JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(500, 300)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); listPanel.add(scrollPane, BorderLayout.CENTER); JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) { public void actionPerformed(ActionEvent e) { final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory()); if (inFile == null) return; try { final File tmpDir = new File(serverDir, "tmp"); tmpDir.mkdir(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.unzip(inFile, tmpDir, progress); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); File tmpFile = new File(tmpDir, "index.tmp"); ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile)); String bookFile = input.readUTF(); String bookName = input.readUTF(); String bookDesc = input.readUTF(); input.close(); new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc, new File(tmpDir, bookFile)); FileUtils.cleanDirectory(tmpDir); FileUtils.deleteDirectory(tmpDir); updateBooks(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } })); listPanel.add(importPanel, BorderLayout.SOUTH); add(listPanel); JPanel setupPanel = new JPanel( new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); setupPanel.setBorder( BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel"))); usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel")); usedBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book != null) { book.used = usedBox.isSelected(); bookList.repaint(); } } }); setupPanel.add(usedBox); JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel"))); nameField = new JTextField(50); nameField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.name = nameField.getText(); bookList.repaint(); } }); fieldPanel.add(nameField); fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel"))); descField = new JTextPane(); //descField.setWrapStyleWord(true); descField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { changedUpdate(e); } public void insertUpdate(DocumentEvent e) { changedUpdate(e); } public void changedUpdate(DocumentEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.desc = descField.getText(); } }); scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(420, 50)); scrollPane.getVerticalScrollBar().setUnitIncrement(10); fieldPanel.add(scrollPane); setupPanel.add(fieldPanel); exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) { public void actionPerformed(ActionEvent e) { File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory()); if (file == null) return; final Book book = (Book) bookList.getSelectedValue(); final File indexFile = new File(serverDir, "index.tmp"); try { final File outFile = file; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile)); out.writeUTF(book.bookFile.getName()); out.writeUTF(book.name); out.writeUTF(book.desc); out.close(); GuiUtils.blockUntilComplete(new ProgressRunnable() { float[] progress = { 0 }; public void run() { try { ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir }, outFile, progress, 0, 1, 9); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) progress[0]; } }, ServerConfigPanel.this); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } if (indexFile.exists()) indexFile.delete(); } }); deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) { public void actionPerformed(ActionEvent e) { Book book = (Book) bookList.getSelectedValue(); if (book == null) return; book.deleted = !book.deleted; bookList.repaint(); } }); JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); actionsPanel.add(exportButton); actionsPanel.add(deleteButton); setupPanel.add(actionsPanel); add(setupPanel); JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT, SwingConstants.TOP, true, false)); optionsPanel .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel"))); JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); timeoutField = new JTextField(5); timeoutPanel.add(timeoutField); timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel"))); optionsPanel.add(timeoutPanel); add(optionsPanel); updateBooks(); setFields(null); final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>"; String idle = StringUtils.getTagContent(xml, "idle"); if (idle != null) try { timeoutField.setText("" + Integer.parseInt(idle)); } catch (Throwable e) { } }
From source file:org.isatools.isacreator.filechooser.FileChooserUI.java
private JPanel createTopPanel() { final JTextField uri = new RoundedJTextField(20); final JTextField username = new RoundedJTextField(20); final JPasswordField password = new RoundedJPasswordField(20); final JPanel topContainer = new JPanel(); topContainer.setLayout(new BoxLayout(topContainer, BoxLayout.PAGE_AXIS)); topContainer.setBackground(UIHelper.BG_COLOR); HUDTitleBar titlePanel = new HUDTitleBar(null, null, true); add(titlePanel, BorderLayout.NORTH); titlePanel.installListeners();//from w w w. j a va2 s . c o m topContainer.add(titlePanel); JPanel buttonPanel = new JPanel(new GridLayout(1, 1)); buttonPanel.setOpaque(false); JPanel fileSystemPanel = new JPanel(); fileSystemPanel.setLayout(new BoxLayout(fileSystemPanel, BoxLayout.LINE_AXIS)); fileSystemPanel.setBackground(UIHelper.BG_COLOR); localFsChoice = new JLabel(localFileSystemIcon, JLabel.LEFT); localFsChoice.setBackground(UIHelper.BG_COLOR); localFsChoice.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { localFsChoice.setIcon(localFileSystemIconOver); remoteFsChoice.setIcon(remoteFileSystemIcon); ftpConnectionContainer.setVisible(false); topContainer.revalidate(); status.setText(""); fileBrowser = new LocalBrowser(); try { updateTree(fileBrowser.getHomeDirectory()); } catch (IOException e) { FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false, FileBrowserTreeNode.DIRECTORY); updateTree(defaultFTPNode); } } }); } }); fileSystemPanel.add(localFsChoice); fileSystemPanel.add(Box.createHorizontalStrut(5)); remoteFsChoice = new JLabel(remoteFileSystemIcon, JLabel.LEFT); remoteFsChoice.setBackground(UIHelper.BG_COLOR); remoteFsChoice.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { localFsChoice.setIcon(localFileSystemIcon); remoteFsChoice.setIcon(remoteFileSystemIconOver); ftpConnectionContainer.setVisible(true); topContainer.revalidate(); } }); // immediately try to call FTP manager to get last sessions details final FTPAuthentication lastSession; if ((lastSession = ftpManager.getLastSession()) != null) { Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(lastSession.getUri(), lastSession.getUsername(), lastSession.getPassword()); } }); remoteConnector.start(); } else { errorAction("no ftp location"); } } }); fileSystemPanel.add(remoteFsChoice); fileSystemPanel.add(Box.createHorizontalStrut(5)); status = UIHelper.createLabel("", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); status.setHorizontalAlignment(JLabel.RIGHT); fileSystemPanel.add(status); buttonPanel.add(fileSystemPanel); topContainer.add(buttonPanel); // now create panel to configure the FTP site ftpConnectionContainer = new JPanel(new GridLayout(1, 1)); ftpConnectionContainer.setBackground(UIHelper.BG_COLOR); JPanel userAuthFTP = new JPanel(); userAuthFTP.setLayout(new BoxLayout(userAuthFTP, BoxLayout.LINE_AXIS)); userAuthFTP.setOpaque(false); // add field to add URI JPanel uriPanel = new JPanel(new GridLayout(1, 2)); uriPanel.setBackground(UIHelper.BG_COLOR); JLabel uriLab = UIHelper.createLabel("FTP URI: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(uri, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); uriPanel.add(uriLab); uriPanel.add(uri); userAuthFTP.add(uriPanel); // add field to add username JPanel usernamePanel = new JPanel(new GridLayout(1, 2)); usernamePanel.setBackground(UIHelper.BG_COLOR); JLabel usernameLab = UIHelper.createLabel("Username: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(username, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); uriPanel.add(usernameLab); uriPanel.add(username); userAuthFTP.add(usernamePanel); // add field to add password JPanel passwordPanel = new JPanel(new GridLayout(1, 2)); passwordPanel.setBackground(UIHelper.BG_COLOR); JLabel passwordLab = UIHelper.createLabel("Password: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR); UIHelper.renderComponent(password, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false); passwordPanel.add(passwordLab); passwordPanel.add(password); userAuthFTP.add(passwordPanel); JLabel connectLab = new JLabel(connectIcon); connectLab.setOpaque(false); connectLab.setToolTipText("<html><b>Connect</b><p>Connect to the FTP source defined!</p></html>"); connectLab.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); if (uri.getText() != null && !uri.getText().trim().equals("")) { String user = (username.getText() != null) ? username.getText() : ""; String pass = (password.getPassword() != null) ? new String(password.getPassword()) : ""; final FTPAuthentication newFTPLocation = new FTPAuthentication(uri.getText(), user, pass); Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(newFTPLocation.getUri(), newFTPLocation.getUsername(), newFTPLocation.getPassword()); } }); remoteConnector.start(); } } }); userAuthFTP.add(connectLab); JLabel historyLab = new JLabel(viewHistoryIcon); historyLab.setOpaque(false); historyLab.setToolTipText( "<html><b>Search previously connected to FTP locations</b><p>Connect to a previously defined FTP location</p></html>"); historyLab.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); SelectFromFTPHistory selectFTP = new SelectFromFTPHistory(); selectFTP.addPropertyChangeListener("locationSelected", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getNewValue() != null) { final FTPAuthentication ftpRecord = ftpManager .retrieveFTPAuthenticationObject(event.getNewValue().toString()); Thread remoteConnector = new Thread(new Runnable() { public void run() { connectToFTP(ftpRecord.getUri(), ftpRecord.getUsername(), ftpRecord.getPassword()); } }); remoteConnector.start(); } } }); selectFTP.createGUI(); showJDialogAsSheet(selectFTP); } }); userAuthFTP.add(historyLab); ftpConnectionContainer.add(userAuthFTP); ftpConnectionContainer.setVisible(false); topContainer.add(ftpConnectionContainer); return topContainer; }
From source file:org.isatools.isacreator.filechooser.FileChooserUI.java
/** * Creates the FileSelection panel containing the list of selected files, and the toolbar to modify the list * * @return JPanel containing a selection pane *//* w w w. ja v a 2 s. c o m*/ private JPanel createFilesSelectedPanel() { JPanel selectionContainer = new JPanel(new BorderLayout()); selectionContainer.setBackground(UIHelper.BG_COLOR); selectionContainer.setBorder( new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "selection(s)", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR)); selectedFiles = new DirectoryFileList(); listModel = (DefaultListModel) selectedFiles.getModel(); selectedFiles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); selectedFiles.setDragEnabled(false); JScrollPane selectedFileScroller = new JScrollPane(selectedFiles, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); selectedFileScroller.setPreferredSize(new Dimension(200, 175)); selectedFileScroller.setBorder(new EmptyBorder(0, 0, 0, 0)); IAppWidgetFactory.makeIAppScrollPane(selectedFileScroller); selectionContainer.add(selectedFileScroller, BorderLayout.CENTER); // add list modification toolbar to sort, move, and delete files from the list. JPanel optionsPanel = new JPanel(); optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.LINE_AXIS)); optionsPanel.setBackground(UIHelper.BG_COLOR); final JLabel moveDown = new JLabel(downIcon); moveDown.setOpaque(false); moveDown.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { moveDown.setIcon(downIcon); if (!selectedFiles.isSelectionEmpty()) { int toMoveDown = selectedFiles.getSelectedIndex(); if (toMoveDown != (listModel.getSize() - 1)) { swapElements(toMoveDown, toMoveDown + 1); } } } public void mouseEntered(MouseEvent event) { moveDown.setIcon(downIconOver); } public void mouseExited(MouseEvent event) { moveDown.setIcon(downIcon); } }); optionsPanel.add(moveDown); optionsPanel.add(Box.createHorizontalStrut(5)); final JLabel moveUp = new JLabel(upIcon); moveUp.setOpaque(false); moveUp.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { moveUp.setIcon(upIcon); if (!selectedFiles.isSelectionEmpty()) { int toMoveUp = selectedFiles.getSelectedIndex(); if (toMoveUp != 0) { swapElements(toMoveUp, toMoveUp - 1); } } } public void mouseEntered(MouseEvent event) { moveUp.setIcon(upIconOver); } public void mouseExited(MouseEvent event) { moveUp.setIcon(upIcon); } }); optionsPanel.add(moveUp); optionsPanel.add(Box.createHorizontalStrut(5)); final JLabel deleteItem = new JLabel(deleteIcon); deleteItem.setOpaque(false); deleteItem.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { deleteItem.setIcon(deleteIcon); if (selectedFiles.getSelectedValues() != null) { for (Object o : selectedFiles.getSelectedValues()) { listModel.removeElement(o); } } } public void mouseEntered(MouseEvent event) { deleteItem.setIcon(deleteIconOver); } public void mouseExited(MouseEvent event) { deleteItem.setIcon(deleteIcon); } }); optionsPanel.add(deleteItem); optionsPanel.add(Box.createHorizontalStrut(5)); final JLabel sortAsc = new JLabel(sortAscIcon); sortAsc.setOpaque(false); sortAsc.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { sortAsc.setIcon(sortAscIcon); if (listModel.getSize() > 0) { sort(true); } } public void mouseEntered(MouseEvent event) { sortAsc.setIcon(sortAscIconOver); } public void mouseExited(MouseEvent event) { sortAsc.setIcon(sortAscIcon); } }); optionsPanel.add(sortAsc); optionsPanel.add(Box.createHorizontalStrut(5)); final JLabel sortDesc = new JLabel(sortDescIcon); sortDesc.setOpaque(false); sortDesc.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { sortDesc.setIcon(sortDescIcon); if (listModel.getSize() > 0) { sort(false); } } public void mouseEntered(MouseEvent event) { sortDesc.setIcon(sortDescIconOver); } public void mouseExited(MouseEvent event) { sortDesc.setIcon(sortDescIcon); } }); optionsPanel.add(sortDesc); optionsPanel.add(Box.createHorizontalStrut(5)); selectionContainer.add(optionsPanel, BorderLayout.SOUTH); return selectionContainer; }
From source file:org.isatools.isacreator.filechooser.FileChooserUI.java
/** * Create the Navigation Tree panel//from w w w . j a v a 2 s. c o m * * @return @see JPanel containing the navigation tree to browse a file system. */ private JPanel createNavTree() { JPanel treeContainer = new JPanel(new BorderLayout()); treeContainer.setBackground(UIHelper.BG_COLOR); treeContainer .setBorder(new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR)); JPanel navigationControls = new JPanel(); navigationControls.setLayout(new BoxLayout(navigationControls, BoxLayout.LINE_AXIS)); navigationControls.setOpaque(false); final JLabel navToParentDir = new JLabel(upIcon); navToParentDir.setOpaque(false); navToParentDir.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); navToParentDir.setIcon(upIcon); try { updateTree(fileBrowser.getParentDirectory()); } catch (IOException e) { errorAction("problem occurred!"); } } public void mouseEntered(MouseEvent event) { super.mouseEntered(event); navToParentDir.setIcon(upIconOver); } public void mouseExited(MouseEvent event) { super.mouseExited(event); navToParentDir.setIcon(upIcon); } }); navigationControls.add(navToParentDir); navigationControls.add(Box.createHorizontalStrut(5)); final JLabel navToHomeDir = new JLabel(homeIcon); navToHomeDir.setOpaque(false); navToHomeDir.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); navToHomeDir.setIcon(homeIcon); try { updateTree(fileBrowser.getHomeDirectory()); } catch (IOException e) { if (e instanceof ConnectionException) { status.setText("<html>status: not connected!</html>"); } FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false, FileBrowserTreeNode.DIRECTORY); updateTree(defaultFTPNode); } } public void mouseEntered(MouseEvent event) { super.mouseEntered(event); navToHomeDir.setIcon(homeIconOver); } public void mouseExited(MouseEvent event) { super.mouseExited(event); navToHomeDir.setIcon(homeIcon); } }); navigationControls.add(navToHomeDir); navigationControls.add(Box.createGlue()); treeContainer.add(navigationControls, BorderLayout.NORTH); try { treeModel = new DefaultTreeModel(fileBrowser.getHomeDirectory()); directoryTree = new JTree(treeModel); directoryTree.setFont(UIHelper.VER_11_PLAIN); directoryTree.setCellRenderer(new FileSystemTreeCellRenderer()); } catch (IOException e) { FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false, FileBrowserTreeNode.DIRECTORY); updateTree(defaultFTPNode); } directoryTree.addMouseListener(new CommonMouseAdapter() { public void mousePressed(MouseEvent event) { super.mousePressed(event); int selRow = directoryTree.getRowForLocation(event.getX(), event.getY()); TreePath selPath = directoryTree.getPathForLocation(event.getX(), event.getY()); if (selRow != -1) { final FileBrowserTreeNode node = (FileBrowserTreeNode) selPath.getLastPathComponent(); if (SwingUtilities.isLeftMouseButton(event)) { if (event.getClickCount() == 2) { if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) { String newPath; if (fileBrowser instanceof LocalBrowser) { newPath = ((File) fileBrowser.getDirFiles().get(node.toString())).getPath(); } else { newPath = node.toString(); } updateTree(fileBrowser.changeDirectory(newPath)); } // else, if a leaf node, then add file to to list if (node.isLeaf() && (node.getType() != FileBrowserTreeNode.DIRECTORY)) { String extension = node.toString().substring(node.toString().lastIndexOf(".") + 1) .trim().toUpperCase(); FileChooserFile toAdd = null; for (Object o : fileBrowser.getFileMap().get(extension)) { String fileName; String filePath; if (fileBrowser instanceof LocalBrowser) { File file = (File) o; fileName = file.getName(); filePath = file.getPath(); if (fileName.equals(node.toString())) { toAdd = new CustomFile(filePath); break; } } else { FTPFile ftpFile = (FTPFile) o; fileName = ftpFile.getName(); filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator + ftpFile.getName(); if (fileName.equals(node.toString())) { toAdd = new CustomFTPFile(ftpFile, filePath); break; } } } if (toAdd != null && !checkIfInList(toAdd)) { selectedFiles.addFileItem(toAdd); } } } } else { if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) { // show popup to add the directory to the selected files JPopupMenu popup = new JPopupMenu(); JMenuItem addDirectory = new JMenuItem("add directory"); addDirectory.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { Object fileToAdd = fileBrowser.getDirFiles().get(node.toString()); FileChooserFile toAdd; if (fileToAdd instanceof File) { toAdd = new CustomFile(((File) fileToAdd).getPath()); } else { FTPFile ftpFile = (FTPFile) fileToAdd; String filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator + ftpFile.getName(); toAdd = new CustomFTPFile(ftpFile, filePath); } if (!checkIfInList(toAdd)) { selectedFiles.addDirectoryItem(toAdd); } } }); popup.add(addDirectory); popup.show(directoryTree, event.getX(), event.getY()); } } } } }); BasicTreeUI ui = new BasicTreeUI() { public Icon getCollapsedIcon() { return null; } public Icon getExpandedIcon() { return null; } }; directoryTree.setUI(ui); directoryTree.setFont(UIHelper.VER_12_PLAIN); JScrollPane treeScroll = new JScrollPane(directoryTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); treeScroll.setPreferredSize(new Dimension(300, 200)); treeScroll.setBorder(new EmptyBorder(0, 0, 0, 0)); treeContainer.add(treeScroll, BorderLayout.CENTER); IAppWidgetFactory.makeIAppScrollPane(treeScroll); return treeContainer; }