List of usage examples for javax.swing JButton setCursor
public void setCursor(Cursor cursor)
From source file:Main.java
/** * Configures a button as if it was an hyperlink. * // w w w . java 2 s . c om * @param button * the button to configure. */ public static void configureButtonAsHyperlink(JButton button) { if (button == null) { return; } StringBuffer html = new StringBuffer(); html.append("<html><font color=\"blue\"><u>"); html.append(button.getText()); html.append("</u></font></html>"); button.setText(html.toString()); button.setMargin(new Insets(0, 0, 0, 0)); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFocusPainted(false); button.setBorderPainted(false); button.setContentAreaFilled(false); }
From source file:TextSamplerDemo.java
protected void addStylesToDocument(StyledDocument doc) { //Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); s = doc.addStyle("small", regular); StyleConstants.setFontSize(s, 10); s = doc.addStyle("large", regular); StyleConstants.setFontSize(s, 16); s = doc.addStyle("icon", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon pigIcon = createImageIcon("images/Pig.gif", "a cute pig"); if (pigIcon != null) { StyleConstants.setIcon(s, pigIcon); }// w w w . j av a2 s. c o m s = doc.addStyle("button", regular); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); ImageIcon soundIcon = createImageIcon("images/sound.gif", "sound icon"); JButton button = new JButton(); if (soundIcon != null) { button.setIcon(soundIcon); } else { button.setText("BEEP"); } button.setCursor(Cursor.getDefaultCursor()); button.setMargin(new Insets(0, 0, 0, 0)); button.setActionCommand(buttonString); button.addActionListener(this); StyleConstants.setComponent(s, button); }
From source file:net.technicpack.launcher.ui.InstallerFrame.java
private void initComponents() { setSize(DIALOG_WIDTH, DIALOG_HEIGHT); setIconImage(resources.getImage("icon.png")); setLayout(new BorderLayout()); JPanel header = new JPanel(); header.setBackground(Color.black); header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS)); header.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8)); add(header, BorderLayout.PAGE_START); JLabel title = new JLabel(resources.getString("launcher.installer.title")); title.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 34)); title.setForeground(LauncherFrame.COLOR_WHITE_TEXT); title.setOpaque(false);/*from w w w . j av a2 s.c om*/ title.setIcon(resources.getIcon("options_cog.png")); header.add(title); header.add(Box.createHorizontalGlue()); JButton closeButton = new JButton(); closeButton.setIcon(resources.getIcon("close.png")); closeButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); closeButton.setContentAreaFilled(false); closeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); closeButton.setFocusPainted(false); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { mainFrame.setVisible(true); dispose(); } }); header.add(closeButton); SimpleTabPane centerPanel = new SimpleTabPane(); centerPanel.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL); centerPanel.setForeground(LauncherFrame.COLOR_GREY_TEXT); centerPanel.setSelectedBackground(LauncherFrame.COLOR_BLUE); centerPanel.setSelectedForeground(LauncherFrame.COLOR_WHITE_TEXT); centerPanel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14)); centerPanel.setOpaque(true); add(centerPanel, BorderLayout.CENTER); JPanel standardInstallPanel = new JPanel(); standardInstallPanel.setBackground(LauncherFrame.COLOR_CENTRAL_BACK_OPAQUE); setupStandardInstall(standardInstallPanel); JPanel portableModePanel = new JPanel(); portableModePanel.setBackground(LauncherFrame.COLOR_CENTRAL_BACK_OPAQUE); setupPortableMode(portableModePanel); centerPanel.addTab(resources.getString("launcher.installer.standard").toUpperCase(), standardInstallPanel); centerPanel.addTab(resources.getString("launcher.installer.portable").toUpperCase(), portableModePanel); if (settings.isPortable()) { centerPanel.setSelectedIndex(1); } else centerPanel.setSelectedIndex(0); setLocationRelativeTo(null); }
From source file:net.technicpack.launcher.ui.LauncherFrame.java
private void initComponents() { BorderLayout layout = new BorderLayout(); setLayout(layout);/*www .j a v a2 s .co m*/ ///////////////////////////////////////////////////////////// //HEADER ///////////////////////////////////////////////////////////// JPanel header = new JPanel(); header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS)); header.setBackground(COLOR_BLUE); header.setForeground(COLOR_WHITE_TEXT); header.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 10)); this.add(header, BorderLayout.PAGE_START); ImageIcon headerIcon = resources.getIcon("platform_icon_title.png"); JButton headerLabel = new JButton(headerIcon); headerLabel.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 0)); headerLabel.setContentAreaFilled(false); headerLabel.setFocusPainted(false); headerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); headerLabel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DesktopUtils.browseUrl("http://beta.technicpack.net/"); } }); header.add(headerLabel); header.add(Box.createRigidArea(new Dimension(6, 0))); ActionListener tabListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectTab(e.getActionCommand()); } }; discoverTab = new HeaderTab(resources.getString("launcher.title.discover"), resources); header.add(discoverTab); discoverTab.setActionCommand(TAB_DISCOVER); discoverTab.addActionListener(tabListener); modpacksTab = new HeaderTab(resources.getString("launcher.title.modpacks"), resources); modpacksTab.setIsActive(true); modpacksTab.setHorizontalTextPosition(SwingConstants.LEADING); modpacksTab.addActionListener(tabListener); modpacksTab.setActionCommand(TAB_MODPACKS); header.add(modpacksTab); newsTab = new HeaderTab(resources.getString("launcher.title.news"), resources); newsTab.setLayout(null); newsTab.addActionListener(tabListener); newsTab.setActionCommand(TAB_NEWS); header.add(newsTab); CountCircle newsCircle = new CountCircle(); newsCircle.setBackground(COLOR_RED); newsCircle.setForeground(COLOR_WHITE_TEXT); newsCircle.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS_BOLD, 14)); newsTab.add(newsCircle); newsCircle.setBounds(10, 17, 25, 25); header.add(Box.createHorizontalGlue()); JPanel rightHeaderPanel = new JPanel(); rightHeaderPanel.setOpaque(false); rightHeaderPanel.setLayout(new BoxLayout(rightHeaderPanel, BoxLayout.PAGE_AXIS)); rightHeaderPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); JPanel windowGadgetPanel = new JPanel(); windowGadgetPanel.setOpaque(false); windowGadgetPanel.setLayout(new BoxLayout(windowGadgetPanel, BoxLayout.LINE_AXIS)); windowGadgetPanel.setAlignmentX(RIGHT_ALIGNMENT); ImageIcon minimizeIcon = resources.getIcon("minimize.png"); JButton minimizeButton = new JButton(minimizeIcon); minimizeButton.setBorder(BorderFactory.createEmptyBorder()); minimizeButton.setContentAreaFilled(false); minimizeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); minimizeButton.setFocusable(false); minimizeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { minimizeWindow(); } }); windowGadgetPanel.add(minimizeButton); ImageIcon closeIcon = resources.getIcon("close.png"); JButton closeButton = new JButton(closeIcon); closeButton.setBorder(BorderFactory.createEmptyBorder()); closeButton.setContentAreaFilled(false); closeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeWindow(); } }); closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); closeButton.setFocusable(false); windowGadgetPanel.add(closeButton); rightHeaderPanel.add(windowGadgetPanel); rightHeaderPanel.add(Box.createVerticalGlue()); JButton launcherOptionsLabel = new JButton(resources.getString("launcher.title.options")); launcherOptionsLabel.setIcon(resources.getIcon("options_cog.png")); launcherOptionsLabel.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 14)); launcherOptionsLabel.setForeground(COLOR_WHITE_TEXT); launcherOptionsLabel.setHorizontalAlignment(SwingConstants.RIGHT); launcherOptionsLabel.setHorizontalTextPosition(SwingConstants.LEADING); launcherOptionsLabel.setAlignmentX(RIGHT_ALIGNMENT); launcherOptionsLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); launcherOptionsLabel.setBorder(BorderFactory.createEmptyBorder()); launcherOptionsLabel.setContentAreaFilled(false); launcherOptionsLabel.setFocusPainted(false); launcherOptionsLabel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openLauncherOptions(); } }); rightHeaderPanel.add(launcherOptionsLabel); header.add(rightHeaderPanel); ///////////////////////////////////////////////////////////// // CENTRAL AREA ///////////////////////////////////////////////////////////// centralPanel = new TintablePanel(); centralPanel.setBackground(COLOR_CHARCOAL); centralPanel.setForeground(COLOR_WHITE_TEXT); centralPanel.setTintColor(COLOR_CENTRAL_BACK); this.add(centralPanel, BorderLayout.CENTER); centralPanel.setLayout(new BorderLayout()); modpackPanel = new ModpackInfoPanel(resources, iconRepo, logoRepo, backgroundRepo, avatarRepo, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openModpackOptions((ModpackModel) e.getSource()); } }, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { refreshModpackOptions((ModpackModel) e.getSource()); } }); modpackSelector.setInfoPanel(modpackPanel); playButton = modpackPanel.getPlayButton(); playButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof ModpackModel) { setupPlayButtonText((ModpackModel) e.getSource(), userModel.getCurrentUser()); } else if (installer.isCurrentlyRunning()) { installer.cancel(); setupPlayButtonText(modpackSelector.getSelectedPack(), userModel.getCurrentUser()); } else { launchModpack(); } } }); modpackPanel.getDeleteButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(LauncherFrame.this, resources.getString("modpackoptions.delete.confirmtext"), resources.getString("modpackoptions.delete.confirmtitle"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { modpackSelector.getSelectedPack().delete(); modpackSelector.forceRefresh(); } } }); infoSwap = new JPanel(); infoLayout = new CardLayout(); infoSwap.setLayout(infoLayout); infoSwap.setOpaque(false); newsInfoPanel = new NewsInfoPanel(resources, avatarRepo); infoSwap.add(discoverInfoPanel, "discover"); JPanel newsHost = new JPanel(); infoSwap.add(newsHost, "news"); JPanel modpackHost = new JPanel(); infoSwap.add(modpackHost, "modpacks"); centralPanel.add(infoSwap, BorderLayout.CENTER); newsSelector = new NewsSelector(resources, newsInfoPanel, platformApi, avatarRepo, newsCircle, settings); newsHost.setLayout(new BorderLayout()); newsHost.add(newsInfoPanel, BorderLayout.CENTER); newsHost.add(newsSelector, BorderLayout.WEST); modpackHost.setLayout(new BorderLayout()); modpackHost.add(modpackPanel, BorderLayout.CENTER); modpackHost.add(modpackSelector, BorderLayout.WEST); footer = new TintablePanel(); footer.setTintColor(COLOR_CENTRAL_BACK); footer.setBackground(COLOR_FOOTER); footer.setLayout(new BoxLayout(footer, BoxLayout.LINE_AXIS)); footer.setForeground(COLOR_WHITE_TEXT); footer.setBorder(BorderFactory.createEmptyBorder(3, 6, 3, 12)); userWidget = new UserWidget(resources, skinRepository); userWidget.setMaximumSize(userWidget.getPreferredSize()); footer.add(userWidget); JLabel dashText = new JLabel("| "); dashText.setForeground(LauncherFrame.COLOR_WHITE_TEXT); dashText.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15)); footer.add(dashText); JButton logout = new JButton(resources.getString("launcher.user.logout")); logout.setBorder(BorderFactory.createEmptyBorder()); logout.setContentAreaFilled(false); logout.setFocusable(false); logout.setForeground(LauncherFrame.COLOR_WHITE_TEXT); logout.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); logout.setFont(resources.getFont(ResourceLoader.FONT_RALEWAY, 15)); logout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logout(); } }); footer.add(logout); installProgress = new ProgressBar(); installProgress.setForeground(Color.white); installProgress.setBackground(LauncherFrame.COLOR_GREEN); installProgress.setBorder(BorderFactory.createEmptyBorder(5, 45, 4, 45)); installProgress.setIcon(resources.getIcon("download_icon.png")); installProgress.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 12)); installProgress.setVisible(false); footer.add(installProgress); installProgressPlaceholder = Box.createHorizontalGlue(); footer.add(installProgressPlaceholder); JLabel buildCtrl = new JLabel(resources.getString("launcher.build.text", resources.getLauncherBuild(), resources.getString("launcher.build." + settings.getBuildStream()))); buildCtrl.setForeground(COLOR_WHITE_TEXT); buildCtrl.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14)); buildCtrl.setHorizontalTextPosition(SwingConstants.RIGHT); buildCtrl.setHorizontalAlignment(SwingConstants.RIGHT); footer.add(buildCtrl); this.add(footer, BorderLayout.PAGE_END); }
From source file:op.allowance.PnlAllowance.java
private JPanel createContentPanel4(final Resident resident, LocalDate month) { final String key = getKey(resident, month); if (!contentmap.containsKey(key)) { JPanel pnlMonth = new JPanel(new VerticalLayout()); pnlMonth.setBackground(getBG(resident, 11)); pnlMonth.setOpaque(false);/*from w w w. j a va 2 s.c o m*/ // final String prevKey = resident.getRID() + "-" + SYSCalendar.eom(month.minusMonths(1)).getYear() + "-" + SYSCalendar.eom(month.minusMonths(1)).getMonthOfYear(); if (!carrySums.containsKey(key)) { carrySums.put(key, AllowanceTools.getSUM(resident, SYSCalendar.eom(month.minusMonths(1)))); } BigDecimal rowsum = carrySums.get(key); if (!cashmap.containsKey(key)) { cashmap.put(key, AllowanceTools.getMonth(resident, month.toDate())); } JLabel lblEOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">" + DateFormat.getDateInstance().format(month.dayOfMonth().withMaximumValue().toDate()) + "</td>" + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.endofmonth") + "</td>" + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">" + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum) + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" + "</font></html>"); pnlMonth.add(lblEOM); for (final Allowance allowance : cashmap.get(key)) { String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">" + DateFormat.getDateInstance().format(allowance.getPit()) + "</td>" + "<td width=\"400\" align=\"left\">" + allowance.getText() + "</td>" + "<td width=\"100\" align=\"right\">" + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(allowance.getAmount()) + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "<td width=\"100\" align=\"right\">" + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum) + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" + "</font></html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { } }); cptitle.getButton().setIcon( allowance.isReplaced() || allowance.isReplacement() ? SYSConst.icon22eraser : null); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { /*** * _____ _ _ _ * | ____|__| (_) |_ * | _| / _` | | __| * | |__| (_| | | |_ * |_____\__,_|_|\__| * */ final JButton btnEdit = new JButton(SYSConst.icon22edit3); btnEdit.setPressedIcon(SYSConst.icon22edit3Pressed); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnEdit.setContentAreaFilled(false); btnEdit.setBorder(null); btnEdit.setToolTipText(SYSTools.xx("admin.residents.cash.btnedit.tooltip")); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popupTX = new JidePopup(); popupTX.setMovable(false); PnlTX pnlTX = getPnlTX(resident, allowance); popupTX.setContentPane(pnlTX); popupTX.removeExcludedComponent(pnlTX); popupTX.setDefaultFocusComponent(pnlTX); popupTX.setOwner(btnEdit); GUITools.showPopup(popupTX, SwingConstants.WEST); } }); cptitle.getRight().add(btnEdit); // you can edit your own entries or you are a manager. once they are replaced or a replacement record, its over. btnEdit.setEnabled((OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, internalClassID) || allowance.getUser().equals(OPDE.getLogin().getUser())) && !allowance.isReplaced() && !allowance.isReplacement()); /*** * _ _ _ _______ __ * | | | |_ __ __| | ___ |_ _\ \/ / * | | | | '_ \ / _` |/ _ \ | | \ / * | |_| | | | | (_| | (_) | | | / \ * \___/|_| |_|\__,_|\___/ |_| /_/\_\ * */ final JButton btnUndoTX = new JButton(SYSConst.icon22undo); btnUndoTX.setPressedIcon(SYSConst.icon22Pressed); btnUndoTX.setAlignmentX(Component.RIGHT_ALIGNMENT); btnUndoTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnUndoTX.setContentAreaFilled(false); btnUndoTX.setBorder(null); btnUndoTX.setToolTipText(SYSTools.xx("admin.residents.cash.btnundotx.tooltip")); btnUndoTX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.undo1") + "<br/><i>" + "<br/><i>" + allowance.getText() + " " + cf.format(allowance.getAmount()) + "</i><br/>" + SYSTools.xx("misc.questions.undo2"), SYSConst.icon48undo, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Allowance myOldAllowance = em.merge(allowance); Allowance myCancelAllowance = em .merge(new Allowance(myOldAllowance)); em.lock(em.merge(myOldAllowance.getResident()), LockModeType.OPTIMISTIC); em.lock(myOldAllowance, LockModeType.OPTIMISTIC); myOldAllowance.setReplacedBy(myCancelAllowance, em.merge(OPDE.getLogin().getUser())); em.getTransaction().commit(); DateTime txDate = new DateTime(myCancelAllowance.getPit()); final String keyMonth = myCancelAllowance.getResident().getRID() + "-" + txDate.getYear() + "-" + txDate.getMonthOfYear(); contentmap.remove(keyMonth); cpMap.remove(keyMonth); cashmap.get(keyMonth).remove(allowance); cashmap.get(keyMonth).add(myOldAllowance); cashmap.get(keyMonth).add(myCancelAllowance); Collections.sort(cashmap.get(keyMonth)); updateCarrySums(myCancelAllowance); createCP4(myCancelAllowance.getResident()); try { cpMap.get(keyMonth).setCollapsed(false); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } buildPanel(); } 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(btnUndoTX); btnUndoTX.setEnabled(!allowance.isReplaced() && !allowance.isReplacement()); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { /*** * ____ _ _ * | _ \ ___| | ___| |_ ___ * | | | |/ _ \ |/ _ \ __/ _ \ * | |_| | __/ | __/ || __/ * |____/ \___|_|\___|\__\___| * */ final JButton btnDelete = new JButton(SYSConst.icon22delete); btnDelete.setPressedIcon(SYSConst.icon22deletePressed); btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelete.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnDelete.setContentAreaFilled(false); btnDelete.setBorder(null); btnDelete.setToolTipText(SYSTools.xx("admin.residents.cash.btndelete.tooltip")); btnDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><i>" + allowance.getText() + " " + cf.format(allowance.getAmount()) + "</i><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Allowance myAllowance = em.merge(allowance); em.lock(em.merge(myAllowance.getResident()), LockModeType.OPTIMISTIC); Allowance theOtherOne = null; // Check for special cases if (myAllowance.isReplacement()) { theOtherOne = em.merge(myAllowance.getReplacementFor()); theOtherOne.setReplacedBy(null); theOtherOne.setEditedBy(null); myAllowance.setEditPit(null); } if (myAllowance.isReplaced()) { theOtherOne = em.merge(myAllowance.getReplacedBy()); theOtherOne.setReplacementFor(null); } em.remove(myAllowance); em.getTransaction().commit(); DateTime txDate = new DateTime(myAllowance.getPit()); final String keyMonth = myAllowance.getResident().getRID() + "-" + txDate.getYear() + "-" + txDate.getMonthOfYear(); cpMap.remove(keyMonth); cashmap.get(keyMonth).remove(myAllowance); if (theOtherOne != null) { cashmap.get(keyMonth).remove(theOtherOne); cashmap.get(keyMonth).add(theOtherOne); Collections.sort(cashmap.get(keyMonth)); } // only to update the carrysums. myAllowance will be discarded soon. myAllowance.setAmount(myAllowance.getAmount().negate()); updateCarrySums(myAllowance); createCP4(myAllowance.getResident()); try { if (cpMap.containsKey(keyMonth)) { cpMap.get(keyMonth).setCollapsed(false); } } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } buildPanel(); } 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(btnDelete); } pnlMonth.add(cptitle.getMain()); linemap.put(allowance, cptitle.getMain()); rowsum = rowsum.subtract(allowance.getAmount()); } JLabel lblBOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">" + DateFormat.getDateInstance().format(month.dayOfMonth().withMinimumValue().toDate()) + "</td>" + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.startofmonth") + "</td>" + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">" + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum) + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" + "</font></html>"); lblBOM.setBackground(getBG(resident, 11)); pnlMonth.add(lblBOM); contentmap.put(key, pnlMonth); } return contentmap.get(key); }
From source file:op.care.bhp.PnlBHP.java
private java.util.List<Component> addFilter() { java.util.List<Component> list = new ArrayList<Component>(); jdcDatum = new JDateChooser(new Date()); jdcDatum.setFont(new Font("Arial", Font.PLAIN, 18)); jdcDatum.setMinSelectableDate(BHPTools.getMinDatum(resident)); jdcDatum.setBackground(Color.WHITE); jdcDatum.addPropertyChangeListener(new PropertyChangeListener() { @Override/*from w ww . ja va 2 s. c o m*/ public void propertyChange(PropertyChangeEvent evt) { if (initPhase) { return; } if (evt.getPropertyName().equals("date")) { reloadDisplay(); } } }); list.add(jdcDatum); JPanel buttonPanel = new JPanel(); buttonPanel.setBackground(Color.WHITE); buttonPanel.setLayout(new HorizontalLayout(5)); buttonPanel.setBorder(new EmptyBorder(0, 0, 0, 0)); JButton homeButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start.png"))); homeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { jdcDatum.setDate(jdcDatum.getMinSelectableDate()); } }); homeButton.setPressedIcon( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start_pressed.png"))); homeButton.setBorder(null); homeButton.setBorderPainted(false); homeButton.setOpaque(false); homeButton.setContentAreaFilled(false); homeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JButton backButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back.png"))); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { DateMidnight current = new DateMidnight(jdcDatum.getDate()); DateMidnight min = new DateMidnight(jdcDatum.getMinSelectableDate()); if (current.equals(min)) { return; } jdcDatum.setDate(SYSCalendar.addDate(jdcDatum.getDate(), -1)); } }); backButton .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back_pressed.png"))); backButton.setBorder(null); backButton.setBorderPainted(false); backButton.setOpaque(false); backButton.setContentAreaFilled(false); backButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JButton fwdButton = new JButton(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play.png"))); fwdButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { DateMidnight current = new DateMidnight(jdcDatum.getDate()); if (current.equals(new DateMidnight())) { return; } jdcDatum.setDate(SYSCalendar.addDate(jdcDatum.getDate(), 1)); } }); fwdButton .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play_pressed.png"))); fwdButton.setBorder(null); fwdButton.setBorderPainted(false); fwdButton.setOpaque(false); fwdButton.setContentAreaFilled(false); fwdButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); JButton endButton = new JButton(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end.png"))); endButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { jdcDatum.setDate(new Date()); } }); endButton.setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end_pressed.png"))); endButton.setBorder(null); endButton.setBorderPainted(false); endButton.setOpaque(false); endButton.setContentAreaFilled(false); endButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); buttonPanel.add(homeButton); buttonPanel.add(backButton); buttonPanel.add(fwdButton); buttonPanel.add(endButton); list.add(buttonPanel); // panelFilter.setContentPane(labelPanel); return list; }
From source file:op.care.dfn.PnlDFN.java
private List<Component> addFilters() { List<Component> list = new ArrayList<Component>(); jdcDate = new JDateChooser(new Date()); jdcDate.setFont(new Font("Arial", Font.PLAIN, 14)); jdcDate.setBackground(Color.WHITE); list.add(jdcDate);/*ww w.jav a 2s. c om*/ JPanel buttonPanel = new JPanel(); buttonPanel.setBackground(Color.WHITE); buttonPanel.setLayout(new HorizontalLayout(5)); buttonPanel.setBorder(new EmptyBorder(0, 0, 0, 0)); final JButton homeButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start.png"))); homeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { jdcDate.setDate(jdcDate.getMinSelectableDate()); } }); homeButton.setPressedIcon( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start_pressed.png"))); homeButton.setBorder(null); homeButton.setBorderPainted(false); homeButton.setOpaque(false); homeButton.setContentAreaFilled(false); homeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final JButton backButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back.png"))); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { DateMidnight current = new DateMidnight(jdcDate.getDate()); DateMidnight min = new DateMidnight(jdcDate.getMinSelectableDate()); if (current.equals(min)) { return; } jdcDate.setDate(SYSCalendar.addDate(jdcDate.getDate(), -1)); } }); backButton .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back_pressed.png"))); backButton.setBorder(null); backButton.setBorderPainted(false); backButton.setOpaque(false); backButton.setContentAreaFilled(false); backButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final JButton fwdButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play.png"))); fwdButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { DateMidnight current = new DateMidnight(jdcDate.getDate()); if (current.equals(new DateMidnight())) { return; } jdcDate.setDate(SYSCalendar.addDate(jdcDate.getDate(), 1)); } }); fwdButton .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play_pressed.png"))); fwdButton.setBorder(null); fwdButton.setBorderPainted(false); fwdButton.setOpaque(false); fwdButton.setContentAreaFilled(false); fwdButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); final JButton endButton = new JButton( new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end.png"))); endButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { jdcDate.setDate(new Date()); } }); endButton.setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end_pressed.png"))); endButton.setBorder(null); endButton.setBorderPainted(false); endButton.setOpaque(false); endButton.setContentAreaFilled(false); endButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); buttonPanel.add(homeButton); buttonPanel.add(backButton); buttonPanel.add(fwdButton); buttonPanel.add(endButton); list.add(buttonPanel); jdcDate.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (initPhase) { return; } if (evt.getPropertyName().equals("date")) { reloadDisplay(); } } }); return list; }
From source file:op.care.med.inventory.PnlInventory.java
private CollapsiblePane createCP4(final MedInventory inventory) { /***// w w w. j a v a2 s . c om * _ ____ ____ _ _ _____ _ __ * ___ _ __ ___ __ _| |_ ___ / ___| _ \| || | / /_ _|_ ____ _____ _ __ | |_ ___ _ __ _ \ \ * / __| '__/ _ \/ _` | __/ _ \ | | |_) | || |_| | | || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | | * | (__| | | __/ (_| | || __/ |___| __/|__ _| | | || | | \ V / __/ | | | || (_) | | | |_| | | * \___|_| \___|\__,_|\__\___|\____|_| |_| | ||___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | | * \_\ |___/_/ */ final String key = inventory.getID() + ".xinventory"; synchronized (cpMap) { if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try { cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } cpMap.get(key).setName("inventory"); // final CollapsiblePane cpInventory = cpMap.get(key); BigDecimal sumInventory = BigDecimal.ZERO; try { EntityManager em = OPDE.createEM(); sumInventory = MedInventoryTools.getSum(em, inventory); em.close(); } catch (Exception e) { OPDE.fatal(e); } String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"520\" align=\"left\"><font size=+1>" + inventory.getText() + "</font></td>" + "<td width=\"200\" align=\"right\"><font size=+1>" + NumberFormat.getNumberInstance().format(sumInventory) + " " + DosageFormTools.getPackageText(MedInventoryTools.getForm(inventory)) + "</font></td>" + "</tr>" + "</table>" + "</html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cpMap.get(key).setCollapsed(!cpMap.get(key).isCollapsed()); } catch (PropertyVetoException pve) { // BAH! } } }); cpMap.get(key).setTitleLabelComponent(cptitle.getMain()); cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH); cptitle.getButton().setIcon(inventory.isClosed() ? SYSConst.icon22stopSign : null); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) { /*** * ____ _ ___ _ * / ___| | ___ ___ ___|_ _|_ ____ _____ _ __ | |_ ___ _ __ _ _ * | | | |/ _ \/ __|/ _ \| || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | * | |___| | (_) \__ \ __/| || | | \ V / __/ | | | || (_) | | | |_| | * \____|_|\___/|___/\___|___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | * |___/ */ final JButton btnCloseInventory = new JButton(SYSConst.icon22playerStop); btnCloseInventory.setPressedIcon(SYSConst.icon22playerStopPressed); btnCloseInventory.setAlignmentX(Component.RIGHT_ALIGNMENT); btnCloseInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnCloseInventory.setContentAreaFilled(false); btnCloseInventory.setBorder(null); btnCloseInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btncloseinventory.tooltip")); btnCloseInventory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("nursingrecords.inventory.question.close1") + "<br/><b>" + inventory.getText() + "</b>" + "<br/>" + SYSTools.xx("nursingrecords.inventory.question.close2"), SYSConst.icon48playerStop, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedInventory myInventory = em.merge(inventory); em.lock(myInventory, LockModeType.OPTIMISTIC); em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC); // close all stocks for (MedStock stock : MedStockTools.getAll(myInventory)) { if (!stock.isClosed()) { MedStock mystock = em.merge(stock); em.lock(mystock, LockModeType.OPTIMISTIC); mystock.setNextStock(null); MedStockTools.close(em, mystock, SYSTools.xx( "nursingrecords.inventory.stock.msg.inventory_closed"), MedStockTransactionTools.STATE_EDIT_INVENTORY_CLOSED); } } // close inventory myInventory.setTo(new Date()); em.getTransaction().commit(); createCP4(myInventory); buildPanel(); } 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(); } } } }); } }); btnCloseInventory.setEnabled(!inventory.isClosed()); cptitle.getRight().add(btnCloseInventory); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) { /*** * ____ _ ___ _ * | _ \ ___| |_ _|_ ____ _____ _ __ | |_ ___ _ __ _ _ * | | | |/ _ \ || || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | * | |_| | __/ || || | | \ V / __/ | | | || (_) | | | |_| | * |____/ \___|_|___|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | * |___/ */ final JButton btnDelInventory = new JButton(SYSConst.icon22delete); btnDelInventory.setPressedIcon(SYSConst.icon22deletePressed); btnDelInventory.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnDelInventory.setContentAreaFilled(false); btnDelInventory.setBorder(null); btnDelInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btndelinventory.tooltip")); btnDelInventory.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("nursingrecords.inventory.question.delete1") + "<br/><b>" + inventory.getText() + "</b>" + "<br/>" + SYSTools.xx("nursingrecords.inventory.question.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedInventory myInventory = em.merge(inventory); em.lock(myInventory, LockModeType.OPTIMISTIC); em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC); em.remove(myInventory); em.getTransaction().commit(); // lstInventories.remove(inventory); buildPanel(); } 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(btnDelInventory); } final JToggleButton tbClosedStock = GUITools.getNiceToggleButton(null); tbClosedStock.setToolTipText(SYSTools.xx("nursingrecords.inventory.showclosedstocks")); if (!inventory.isClosed()) { tbClosedStock.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } }); } tbClosedStock.setSelected(inventory.isClosed()); tbClosedStock.setEnabled(!inventory.isClosed()); mapKey2ClosedToggleButton.put(key, tbClosedStock); cptitle.getRight().add(tbClosedStock); CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } }; synchronized (cpListener) { if (cpListener.containsKey(key)) { cpMap.get(key).removeCollapsiblePaneListener(cpListener.get(key)); } cpListener.put(key, adapter); cpMap.get(key).addCollapsiblePaneListener(adapter); } if (!cpMap.get(key).isCollapsed()) { cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected())); } cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING); cpMap.get(key).setOpaque(false); cpMap.get(key).setBackground(getColor(SYSConst.medium2, lstInventories.indexOf(inventory) % 2 != 0)); return cpMap.get(key); } }
From source file:op.care.med.inventory.PnlInventory.java
private CollapsiblePane createCP4(final MedStock stock) { /***//from w w w . j a va2 s . co m * _ ____ ____ _ _ __ _ _ __ * ___ _ __ ___ __ _| |_ ___ / ___| _ \| || | / /__| |_ ___ ___| | _\ \ * / __| '__/ _ \/ _` | __/ _ \ | | |_) | || |_| / __| __/ _ \ / __| |/ /| | * | (__| | | __/ (_| | || __/ |___| __/|__ _| \__ \ || (_) | (__| < | | * \___|_| \___|\__,_|\__\___|\____|_| |_| | |___/\__\___/ \___|_|\_\| | * \_\ /_/ */ final String key = stock.getID() + ".xstock"; synchronized (cpMap) { if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try { cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } cpMap.get(key).setName("stock"); BigDecimal sumStock = BigDecimal.ZERO; try { EntityManager em = OPDE.createEM(); sumStock = MedStockTools.getSum(em, stock); em.close(); } catch (Exception e) { OPDE.fatal(e); } String title = "<html><table border=\"0\">" + "<tr>" + (stock.isClosed() ? "<s>" : "") + "<td width=\"600\" align=\"left\">" + MedStockTools.getAsHTML(stock) + "</td>" + "<td width=\"200\" align=\"right\">" + NumberFormat.getNumberInstance().format(sumStock) + " " + DosageFormTools.getPackageText(MedInventoryTools.getForm(stock.getInventory())) + "</td>" + (stock.isClosed() ? "</s>" : "") + "</tr>" + "</table>" + "</html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cpMap.get(key).setCollapsed(!cpMap.get(key).isCollapsed()); } catch (PropertyVetoException pve) { // BAH! } } }); cpMap.get(key).setTitleLabelComponent(cptitle.getMain()); cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH); cptitle.getRight().add(new StockPanel(stock)); if (!stock.getInventory().isClosed()) { /*** * ____ _ _ _ _ _ * | _ \ _ __(_)_ __ | |_| | __ _| |__ ___| | * | |_) | '__| | '_ \| __| | / _` | '_ \ / _ \ | * | __/| | | | | | | |_| |__| (_| | |_) | __/ | * |_| |_| |_|_| |_|\__|_____\__,_|_.__/ \___|_| * */ final JButton btnPrintLabel = new JButton(SYSConst.icon22print2); btnPrintLabel.setPressedIcon(SYSConst.icon22print2Pressed); btnPrintLabel.setAlignmentX(Component.RIGHT_ALIGNMENT); btnPrintLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnPrintLabel.setContentAreaFilled(false); btnPrintLabel.setBorder(null); btnPrintLabel.setToolTipText(SYSTools.xx("nursingrecords.inventory.stock.btnprintlabel.tooltip")); btnPrintLabel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { LogicalPrinter logicalPrinter = OPDE.getLogicalPrinters().getMapName2LogicalPrinter() .get(OPDE.getProps().getProperty(SYSPropsTools.KEY_LOGICAL_PRINTER)); PrinterForm printerForm1 = logicalPrinter.getForms() .get(OPDE.getProps().getProperty(SYSPropsTools.KEY_MEDSTOCK_LABEL)); OPDE.getPrintProcessor().addPrintJob(new PrintListElement(stock, logicalPrinter, printerForm1, OPDE.getProps().getProperty(SYSPropsTools.KEY_PHYSICAL_PRINTER))); } }); btnPrintLabel.setEnabled(OPDE.getPrintProcessor().isWorking()); cptitle.getRight().add(btnPrintLabel); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); // btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(stock); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); cptitle.getRight().add(btnMenu); CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { cpMap.get(key).setContentPane(createContentPanel4(stock)); } }; synchronized (cpListener) { if (cpListener.containsKey(key)) { cpMap.get(key).removeCollapsiblePaneListener(cpListener.get(key)); } cpListener.put(key, adapter); cpMap.get(key).addCollapsiblePaneListener(adapter); } if (!cpMap.get(key).isCollapsed()) { JPanel contentPane = createContentPanel4(stock); cpMap.get(key).setContentPane(contentPane); } cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING); cpMap.get(key).setOpaque(false); cpMap.get(key).setBackground( getColor(SYSConst.light3, lstInventories.indexOf(stock.getInventory()) % 2 != 0)); return cpMap.get(key); } }
From source file:op.care.med.inventory.PnlInventory.java
private JPanel createContentPanel4(final MedStock stock) { // final String key = stock.getID() + ".xstock"; // if (!contentmap.containsKey(key)) { final JPanel pnlTX = new JPanel(new VerticalLayout()); // pnlTX.setLayout(new BoxLayout(pnlTX, BoxLayout.PAGE_AXIS)); pnlTX.setOpaque(true);/*from w w w . ja va 2 s .c o m*/ // pnlTX.setBackground(Color.white); synchronized (lstInventories) { pnlTX.setBackground(getColor(SYSConst.light2, lstInventories.indexOf(stock.getInventory()) % 2 != 0)); } /*** * _ _ _ _______ __ * / \ __| | __| |_ _\ \/ / * / _ \ / _` |/ _` | | | \ / * / ___ \ (_| | (_| | | | / \ * /_/ \_\__,_|\__,_| |_| /_/\_\ * */ JideButton btnAddTX = GUITools.createHyperlinkButton("nursingrecords.inventory.newmedstocktx", SYSConst.icon22add, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new DlgTX(new MedStockTransaction(stock, BigDecimal.ONE, MedStockTransactionTools.STATE_EDIT_MANUAL), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); final MedStockTransaction myTX = (MedStockTransaction) em.merge(o); MedStock myStock = em.merge(stock); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.lock(em.merge(myTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.getTransaction().commit(); createCP4(myStock.getInventory()); buildPanel(); } 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(); } } } }); } }); btnAddTX.setEnabled(!stock.isClosed()); pnlTX.add(btnAddTX); /*** * ____ _ _ _ _______ __ * / ___|| |__ _____ __ __ _| | | |_ _\ \/ /___ * \___ \| '_ \ / _ \ \ /\ / / / _` | | | | | \ // __| * ___) | | | | (_) \ V V / | (_| | | | | | / \\__ \ * |____/|_| |_|\___/ \_/\_/ \__,_|_|_| |_| /_/\_\___/ * */ OPDE.getMainframe().setBlocked(true); OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100)); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { int progress = 0; List<MedStockTransaction> listTX = MedStockTransactionTools.getAll(stock); OPDE.getDisplayManager().setProgressBarMessage( new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, listTX.size())); BigDecimal rowsum = MedStockTools.getSum(stock); // BigDecimal rowsum = MedStockTools.getSum(stock); // Collections.sort(stock.getStockTransaction()); for (final MedStockTransaction tx : listTX) { progress++; OPDE.getDisplayManager().setProgressBarMessage( new DisplayMessage(SYSTools.xx("misc.msg.wait"), progress, listTX.size())); String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + "<br/>[" + tx.getID() + "]" + "</td>" + "<td width=\"200\" align=\"center\">" + SYSTools.catchNull(tx.getText(), "--") + "</td>" + "<td width=\"100\" align=\"right\">" + NumberFormat.getNumberInstance().format(tx.getAmount()) + "</td>" + "<td width=\"100\" align=\"right\">" + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + NumberFormat.getNumberInstance().format(rowsum) + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + (stock.getTradeForm().isWeightControlled() ? "<td width=\"100\" align=\"right\">" + NumberFormat.getNumberInstance().format(tx.getWeight()) + "g" + "</td>" : "") + "<td width=\"100\" align=\"left\">" + SYSTools.anonymizeUser(tx.getUser().getUID()) + "</td>" + "</tr>" + "</table>" + "</font></html>"; rowsum = rowsum.subtract(tx.getAmount()); final DefaultCPTitle pnlTitle = new DefaultCPTitle(title, null); // pnlTitle.getLeft().addMouseListener(); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) { /*** * ____ _ _______ __ * | _ \ ___| |_ _\ \/ / * | | | |/ _ \ | | | \ / * | |_| | __/ | | | / \ * |____/ \___|_| |_| /_/\_\ * */ final JButton btnDelTX = new JButton(SYSConst.icon22delete); btnDelTX.setPressedIcon(SYSConst.icon22deletePressed); btnDelTX.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnDelTX.setContentAreaFilled(false); btnDelTX.setBorder(null); btnDelTX.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btndelete.tooltip")); btnDelTX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + " " + tx.getUser().getUID() + "</i><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStockTransaction myTX = em.merge(tx); MedStock myStock = em.merge(stock); em.lock(em.merge( myTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.remove(myTX); // myStock.getStockTransaction().remove(myTX); em.getTransaction().commit(); // synchronized (lstInventories) { // int indexInventory = lstInventories.indexOf(stock.getInventory()); // int indexStock = lstInventories.get(indexInventory).getMedStocks().indexOf(stock); // lstInventories.get(indexInventory).getMedStocks().remove(stock); // lstInventories.get(indexInventory).getMedStocks().add(indexStock, myStock); // } // synchronized (linemap) { // linemap.remove(myTX); // } createCP4(myStock.getInventory()); buildPanel(); } 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(); } } } }); } }); btnDelTX.setEnabled( !stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnDelTX); } /*** * _ _ _ _______ __ * | | | |_ __ __| | ___ |_ _\ \/ / * | | | | '_ \ / _` |/ _ \ | | \ / * | |_| | | | | (_| | (_) | | | / \ * \___/|_| |_|\__,_|\___/ |_| /_/\_\ * */ final JButton btnUndoTX = new JButton(SYSConst.icon22undo); btnUndoTX.setPressedIcon(SYSConst.icon22Pressed); btnUndoTX.setAlignmentX(Component.RIGHT_ALIGNMENT); btnUndoTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnUndoTX.setContentAreaFilled(false); btnUndoTX.setBorder(null); btnUndoTX.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btnUndoTX.tooltip")); btnUndoTX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.undo1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(tx.getPit()) + " " + tx.getUser().getUID() + "</i><br/>" + SYSTools.xx("misc.questions.undo2"), SYSConst.icon48undo, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStock myStock = em.merge(stock); final MedStockTransaction myOldTX = em.merge(tx); myOldTX.setState(MedStockTransactionTools.STATE_CANCELLED); final MedStockTransaction myNewTX = em .merge(new MedStockTransaction(myStock, myOldTX.getAmount().negate(), MedStockTransactionTools.STATE_CANCEL_REC)); myOldTX.setText(SYSTools.xx("misc.msg.reversedBy") + ": " + DateFormat .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(myNewTX.getPit())); myNewTX.setText(SYSTools.xx("misc.msg.reversalFor") + ": " + DateFormat .getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT) .format(myOldTX.getPit())); // myStock.getStockTransaction().add(myNewTX); // myStock.getStockTransaction().remove(tx); // myStock.getStockTransaction().add(myOldTX); em.lock(em .merge(myNewTX.getStock().getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.getTransaction().commit(); // synchronized (lstInventories) { // int indexInventory = lstInventories.indexOf(stock.getInventory()); // int indexStock = lstInventories.get(indexInventory).getMedStocks().indexOf(stock); // lstInventories.get(indexInventory).getMedStocks().remove(stock); // lstInventories.get(indexInventory).getMedStocks().add(indexStock, myStock); // } // synchronized (linemap) { // linemap.remove(tx); // } createCP4(myStock.getInventory()); buildPanel(); // SwingUtilities.invokeLater(new Runnable() { // @Override // public void run() { // synchronized (linemap) { // GUITools.flashBackground(linemap.get(myOldTX), Color.RED, 2); // GUITools.flashBackground(linemap.get(myNewTX), Color.YELLOW, 2); // } // } // }); } 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(); } } } }); } }); btnUndoTX.setEnabled(!stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnUndoTX); if (stock.getTradeForm().isWeightControlled() && OPDE.getAppInfo() .isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) { /*** * _ __ __ _ _ _ * ___ ___| |\ \ / /__(_) __ _| |__ | |_ * / __|/ _ \ __\ \ /\ / / _ \ |/ _` | '_ \| __| * \__ \ __/ |_ \ V V / __/ | (_| | | | | |_ * |___/\___|\__| \_/\_/ \___|_|\__, |_| |_|\__| * |___/ */ final JButton btnSetWeight = new JButton(SYSConst.icon22scales); btnSetWeight.setPressedIcon(SYSConst.icon22Pressed); btnSetWeight.setAlignmentX(Component.RIGHT_ALIGNMENT); btnSetWeight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnSetWeight.setContentAreaFilled(false); btnSetWeight.setBorder(null); btnSetWeight.setToolTipText(SYSTools.xx("nursingrecords.inventory.tx.btnUndoTX.tooltip")); btnSetWeight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { BigDecimal weight; new DlgYesNo(SYSConst.icon48scales, new Closure() { @Override public void execute(Object o) { if (!SYSTools.catchNull(o).isEmpty()) { BigDecimal weight = (BigDecimal) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStock myStock = em.merge(stock); final MedStockTransaction myTX = em.merge(tx); em.lock(myTX, LockModeType.OPTIMISTIC); myTX.setWeight(weight); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(myStock.getInventory(), LockModeType.OPTIMISTIC); em.getTransaction().commit(); createCP4(myStock.getInventory()); buildPanel(); } 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(); } } } }, "nursingrecords.bhp.weight", NumberFormat.getNumberInstance().format(tx.getWeight()), 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); } }); } }); btnSetWeight.setEnabled( !stock.isClosed() && (tx.getState() == MedStockTransactionTools.STATE_DEBIT || tx.getState() == MedStockTransactionTools.STATE_CREDIT || tx.getState() == MedStockTransactionTools.STATE_EDIT_MANUAL)); pnlTitle.getRight().add(btnSetWeight); } pnlTX.add(pnlTitle.getMain()); } return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); return pnlTX; }