List of usage examples for javax.swing JMenuBar setBackground
@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.") public void setBackground(Color bg)
From source file:components.TopLevelDemo.java
/** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread./*from w w w. j a v a2s . c o m*/ */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("TopLevelDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create the menu bar. Make it have a green background. JMenuBar greenMenuBar = new JMenuBar(); greenMenuBar.setOpaque(true); greenMenuBar.setBackground(new Color(154, 165, 127)); greenMenuBar.setPreferredSize(new Dimension(200, 20)); //Create a yellow label to put in the content pane. JLabel yellowLabel = new JLabel(); yellowLabel.setOpaque(true); yellowLabel.setBackground(new Color(248, 213, 131)); yellowLabel.setPreferredSize(new Dimension(200, 180)); //Set the menu bar and add the label to the content pane. frame.setJMenuBar(greenMenuBar); frame.getContentPane().add(yellowLabel, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:TopLevelDemo.java
/** * Create the GUI and show it. For thread safety, this method should be * invoked from the event-dispatching thread. *///from ww w .ja v a 2 s. c o m private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("TopLevelDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create the menu bar. Make it have a cyan background. JMenuBar cyanMenuBar = new JMenuBar(); cyanMenuBar.setOpaque(true); cyanMenuBar.setBackground(Color.cyan); cyanMenuBar.setPreferredSize(new Dimension(200, 20)); //Create a yellow label to put in the content pane. JLabel yellowLabel = new JLabel(); yellowLabel.setOpaque(true); yellowLabel.setBackground(Color.yellow); yellowLabel.setPreferredSize(new Dimension(200, 180)); //Set the menu bar and add the label to the content pane. frame.setJMenuBar(cyanMenuBar); frame.getContentPane().add(yellowLabel, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); }
From source file:Main.java
/** * change background and foreground color for menu bar * @param aMenuBar menu bar/*w w w . ja v a 2s . c om*/ * @param aBackgroundColor background color * @param aForegroundColor foreground color */ public final static void ChangeColor(JMenuBar aMenuBar, Color aBackgroundColor, Color aForegroundColor) { if (aBackgroundColor != null) { aMenuBar.setBackground(aBackgroundColor); } if (aForegroundColor != null) { aMenuBar.setForeground(aForegroundColor); } JMenu menu = null; for (int count = 0; count < aMenuBar.getMenuCount(); count++) { menu = aMenuBar.getMenu(count); ChangeColor(menu, aBackgroundColor, aForegroundColor); } }
From source file:imageviewer.system.ImageViewerClient.java
private void initialize(CommandLine args) { // First, process all the different command line arguments that we // need to override and/or send onwards for initialization. boolean fullScreen = (args.hasOption("fullscreen")) ? true : false; String dir = (args.hasOption("dir")) ? args.getOptionValue("dir") : null; String type = (args.hasOption("type")) ? args.getOptionValue("type") : "DICOM"; String prefix = (args.hasOption("client")) ? args.getOptionValue("client") : null; LOG.info("Java home environment: " + System.getProperty("java.home")); // Logging system taken care of through properties file. Check // for JAI. Set up JAI accordingly with the size of the cache // tile and to recycle cached tiles as needed. verifyJAI();//from ww w .j a v a 2 s . c o m TileCache tc = JAI.getDefaultInstance().getTileCache(); tc.setMemoryCapacity(32 * 1024 * 1024); TileScheduler ts = JAI.createTileScheduler(); ts.setPriority(Thread.MAX_PRIORITY); JAI.getDefaultInstance().setTileScheduler(ts); JAI.getDefaultInstance().setRenderingHint(JAI.KEY_CACHED_TILE_RECYCLING_ENABLED, Boolean.TRUE); // Set up the frame and everything else. First, try and set the // UI manager to use our look and feel because it's groovy and // lets us control the GUI components much better. try { UIManager.setLookAndFeel(new ImageViewerLookAndFeel()); LookAndFeelAddons.setAddon(ImageViewerLookAndFeelAddons.class); } catch (Exception exc) { LOG.error("Could not set imageViewer L&F."); } // Load up the ApplicationContext information... ApplicationContext ac = ApplicationContext.getContext(); if (ac == null) { LOG.error("Could not load configuration, exiting."); System.exit(1); } // Override the client node information based on command line // arguments...Make sure that the files are there, otherwise just // default to a local configuration. String hostname = new String("localhost"); try { hostname = InetAddress.getLocalHost().getHostName(); } catch (Exception exc) { } String[] gatewayConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "GatewayConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }); String[] nodeConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "NodeConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }); for (int loop = 0; loop < gatewayConfigs.length; loop++) { String s = gatewayConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG, s); break; } } } LOG.info("Using gateway config: " + ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG)); for (int loop = 0; loop < nodeConfigs.length; loop++) { String s = nodeConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE, s); break; } } } LOG.info("Using client config: " + ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE)); // Load the layouts and set the default window/level manager... LayoutFactory.initialize(); DefaultWindowLevelManager dwlm = new DefaultWindowLevelManager(); // Create the main JFrame, set its behavior, and let the // ApplicationPanel know the glassPane and layeredPane. Set the // menubar based on reading in the configuration menus. mainFrame = new JFrame("imageviewer"); try { ArrayList<Image> iconList = new ArrayList<Image>(); iconList.add(ImageIO.read(new File("resources/icons/mii.png"))); iconList.add(ImageIO.read(new File("resources/icons/mii32.png"))); mainFrame.setIconImages(iconList); } catch (Exception exc) { } mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { int confirm = ApplicationPanel.getInstance().showDialog( "Are you sure you want to quit imageViewer?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, UIManager.getIcon("Dialog.shutdownIcon")); if (confirm == JOptionPane.OK_OPTION) { boolean hasUnsaved = SaveStack.getInstance().hasUnsavedItems(); if (hasUnsaved) { int saveResult = ApplicationPanel.getInstance().showDialog( "There is still unsaved data. Do you want to save this data in the local archive?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); if (saveResult == JOptionPane.CANCEL_OPTION) return; if (saveResult == JOptionPane.YES_OPTION) SaveStack.getInstance().saveAll(); } LOG.info("Shutting down imageServer local archive..."); try { ImageViewerClientNode.getInstance().shutdown(); } catch (Exception exc) { LOG.error("Problem shutting down imageServer local archive..."); } finally { System.exit(0); } } } }); String menuFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_MENUS); String ribbonFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_RIBBON); if (menuFile != null) { JMenuBar mb = new JMenuBar(); mb.setBackground(Color.black); MenuReader.parseFile(menuFile, mb); mainFrame.setJMenuBar(mb); ApplicationContext.getContext().setApplicationMenuBar(mb); } else if (ribbonFile != null) { RibbonReader rr = new RibbonReader(); JRibbon jr = rr.parseFile(ribbonFile); mainFrame.getContentPane().add(jr, BorderLayout.NORTH); ApplicationContext.getContext().setApplicationRibbon(jr); } mainFrame.getContentPane().add(ApplicationPanel.getInstance(), BorderLayout.CENTER); ApplicationPanel.getInstance().setGlassPane((JPanel) (mainFrame.getGlassPane())); ApplicationPanel.getInstance().setLayeredPane(mainFrame.getLayeredPane()); // Load specified plugins...has to occur after the menus are // created, btw. PluginLoader.initialize("config/plugins.xml"); // Detect operating system... String osName = System.getProperty("os.name"); ApplicationContext.getContext().setProperty(ApplicationContext.OS_NAME, osName); LOG.info("Detected operating system: " + osName); // Try and hack the searched library paths if it's windows so we // can add a local dll path... try { if (osName.contains("Windows")) { Field f = ClassLoader.class.getDeclaredField("usr_paths"); f.setAccessible(true); String[] paths = (String[]) f.get(null); String[] tmp = new String[paths.length + 1]; System.arraycopy(paths, 0, tmp, 0, paths.length); File currentPath = new File("."); tmp[paths.length] = currentPath.getCanonicalPath() + "/lib/dll/"; f.set(null, tmp); f.setAccessible(false); } } catch (Exception exc) { LOG.error("Error attempting to dynamically set library paths."); } // Get screen resolution... GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle r = gc.getBounds(); LOG.info("Detected screen resolution: " + (int) r.getWidth() + "x" + (int) r.getHeight()); // Try and see if Java3D is installed, and if so, what version... try { VirtualUniverse vu = new VirtualUniverse(); Map m = vu.getProperties(); String s = (String) m.get("j3d.version"); LOG.info("Detected Java3D version: " + s); } catch (Throwable t) { LOG.info("Unable to detect Java3D installation"); } // Try and see if native JOGL is installed... try { System.loadLibrary("jogl"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.TRUE); LOG.info("Detected native libraries for JOGL"); } catch (Throwable t) { LOG.info("Unable to detect native JOGL installation"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.FALSE); } // Start the local client node to connect to the network and the // local archive running on this machine...Thread the connection // process so it doesn't block the imageViewerClient creating this // instance. We may not be connected to the given gateway, so the // socketServer may go blah... final boolean useNetwork = (args.hasOption("nonet")) ? false : true; ApplicationPanel.getInstance().addStatusMessage("ImageViewer is starting up, please wait..."); if (useNetwork) LOG.info("Starting imageServer client to join network - please wait..."); Thread t = new Thread(new Runnable() { public void run() { try { ImageViewerClientNode.getInstance( (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), useNetwork); ApplicationPanel.getInstance().addStatusMessage("Ready"); } catch (Exception exc) { exc.printStackTrace(); } } }); t.setPriority(9); t.start(); this.fullScreen = fullScreen; mainFrame.setUndecorated(fullScreen); // Set the view to encompass the default screen. if (fullScreen) { Insets i = Toolkit.getDefaultToolkit().getScreenInsets(gc); mainFrame.setLocation(r.x + i.left, r.y + i.top); mainFrame.setSize(r.width - i.left - i.right, r.height - i.top - i.bottom); } else { mainFrame.setSize(1100, 800); mainFrame.setLocation(r.x + 200, r.y + 100); } if (dir != null) ApplicationPanel.getInstance().load(dir, type); timer = new Timer(); timer.schedule(new GarbageCollectionTimer(), 5000, 2500); mainFrame.setVisible(true); }
From source file:lcmc.gui.resources.ServiceInfo.java
/** Returns info panel with comboboxes for service parameters. */ @Override//from ww w. j ava2 s . co m public JComponent getInfoPanel() { if (!getResourceAgent().isMetaDataLoaded()) { final JPanel p = new JPanel(); p.add(new JLabel(Tools.getString("ServiceInfo.LoadingMetaData"))); return p; } final CloneInfo ci = getCloneInfo(); if (ci == null) { getBrowser().getCRMGraph().pickInfo(this); } else { getBrowser().getCRMGraph().pickInfo(ci); } if (infoPanel != null) { return infoPanel; } /* init save button */ final boolean abExisted = getApplyButton() != null; final ServiceInfo thisClass = this; final ButtonCallback buttonCallback = new ButtonCallback() { private volatile boolean mouseStillOver = false; /** * Whether the whole thing should be enabled. */ @Override public final boolean isEnabled() { final Host dcHost = getBrowser().getDCHost(); if (dcHost == null) { return false; } if (Tools.versionBeforePacemaker(dcHost)) { return false; } return true; } @Override public final void mouseOut() { if (!isEnabled()) { return; } mouseStillOver = false; getBrowser().getCRMGraph().stopTestAnimation(getApplyButton()); getApplyButton().setToolTipText(null); } @Override public final void mouseOver() { if (!isEnabled()) { return; } mouseStillOver = true; getApplyButton().setToolTipText(ClusterBrowser.STARTING_PTEST_TOOLTIP); getApplyButton() .setToolTipBackground(Tools.getDefaultColor("ClusterBrowser.Test.Tooltip.Background")); Tools.sleep(250); if (!mouseStillOver) { return; } mouseStillOver = false; final CountDownLatch startTestLatch = new CountDownLatch(1); getBrowser().getCRMGraph().startTestAnimation(getApplyButton(), startTestLatch); final Host dcHost = getBrowser().getDCHost(); getBrowser().ptestLockAcquire(); final ClusterStatus cs = getBrowser().getClusterStatus(); cs.setPtestData(null); apply(dcHost, true); final PtestData ptestData = new PtestData(CRM.getPtest(dcHost)); getApplyButton().setToolTipText(ptestData.getToolTip()); cs.setPtestData(ptestData); getBrowser().ptestLockRelease(); startTestLatch.countDown(); } }; if (getResourceAgent().isGroup()) { initApplyButton(buttonCallback, Tools.getString("Browser.ApplyGroup")); } else { initApplyButton(buttonCallback); } if (ci != null) { ci.setApplyButton(getApplyButton()); ci.setRevertButton(getRevertButton()); } /* add item listeners to the apply button. */ if (!abExisted) { getApplyButton().addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final Thread thread = new Thread(new Runnable() { @Override public void run() { getBrowser().clStatusLock(); apply(getBrowser().getDCHost(), false); getBrowser().clStatusUnlock(); } }); thread.start(); } }); getRevertButton().addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final Thread thread = new Thread(new Runnable() { @Override public void run() { getBrowser().clStatusLock(); revert(); getBrowser().clStatusUnlock(); } }); thread.start(); } }); } /* main, button and options panels */ final JPanel mainPanel = new JPanel(); mainPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); final JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBackground(ClusterBrowser.BUTTON_PANEL_BACKGROUND); buttonPanel.setMinimumSize(new Dimension(0, 50)); buttonPanel.setPreferredSize(new Dimension(0, 50)); buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 50)); final JPanel optionsPanel = new JPanel(); optionsPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); optionsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); /* Actions */ final JMenuBar mb = new JMenuBar(); mb.setBackground(ClusterBrowser.PANEL_BACKGROUND); AbstractButton serviceMenu; if (ci == null) { serviceMenu = getActionsButton(); } else { serviceMenu = ci.getActionsButton(); } buttonPanel.add(serviceMenu, BorderLayout.EAST); String defaultValue = PRIMITIVE_TYPE_STRING; if (ci != null) { if (ci.getService().isMaster()) { defaultValue = MASTER_SLAVE_TYPE_STRING; } else { defaultValue = CLONE_TYPE_STRING; } } if (!getResourceAgent().isClone() && getGroupInfo() == null) { typeRadioGroup = new Widget(defaultValue, new String[] { PRIMITIVE_TYPE_STRING, CLONE_TYPE_STRING, MASTER_SLAVE_TYPE_STRING }, null, /* units */ Widget.Type.RADIOGROUP, null, /* regexp */ ClusterBrowser.SERVICE_LABEL_WIDTH + ClusterBrowser.SERVICE_FIELD_WIDTH, null, /* abbrv */ new AccessMode(ConfigData.AccessType.ADMIN, false)); if (!getService().isNew()) { typeRadioGroup.setEnabled(false); } typeRadioGroup.addListeners(new WidgetListener() { @Override public void check(final Object value) { changeType(((JRadioButton) value).getText()); } }); final JPanel tp = new JPanel(); tp.setBackground(ClusterBrowser.PANEL_BACKGROUND); tp.setLayout(new BoxLayout(tp, BoxLayout.Y_AXIS)); tp.add(typeRadioGroup); typeRadioGroup.setBackgroundColor(ClusterBrowser.PANEL_BACKGROUND); optionsPanel.add(tp); } if (ci != null) { /* add clone fields */ addCloneFields(optionsPanel, ClusterBrowser.SERVICE_LABEL_WIDTH, ClusterBrowser.SERVICE_FIELD_WIDTH); } getResource().setValue(GUI_ID, getService().getId()); /* get dependent resources and create combo boxes for ones, that * need parameters */ final String[] params = getParametersFromXML(); final Info savedMAIdRef = savedMetaAttrInfoRef; addParams(optionsPanel, params, ClusterBrowser.SERVICE_LABEL_WIDTH, ClusterBrowser.SERVICE_FIELD_WIDTH, getSameAsFields(savedMAIdRef)); if (ci == null) { /* score combo boxes */ addHostLocations(optionsPanel, ClusterBrowser.SERVICE_LABEL_WIDTH, ClusterBrowser.SERVICE_FIELD_WIDTH); } for (final String param : params) { if (isMetaAttr(param)) { final Widget wi = getWidget(param, null); wi.setEnabled(savedMAIdRef == null); } } if (!getService().isNew()) { getWidget(GUI_ID, null).setEnabled(false); } if (!getResourceAgent().isGroup() && !getResourceAgent().isClone()) { /* Operations */ addOperations(optionsPanel, ClusterBrowser.SERVICE_LABEL_WIDTH, ClusterBrowser.SERVICE_FIELD_WIDTH); /* add item listeners to the operations combos */ for (final String op : getResourceAgent().getOperationNames()) { for (final String param : getBrowser().getCRMOperationParams(op)) { addOperationListeners(op, param); } } } /* add item listeners to the host scores combos */ if (ci == null) { addHostLocationsListeners(); } else { ci.addHostLocationsListeners(); } /* apply button */ addApplyButton(buttonPanel); addRevertButton(buttonPanel); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { /* invoke later on purpose */ setApplyButtons(null, params); } }); mainPanel.add(optionsPanel); final JPanel newPanel = new JPanel(); newPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); newPanel.setLayout(new BoxLayout(newPanel, BoxLayout.Y_AXIS)); newPanel.add(buttonPanel); newPanel.add( getMoreOptionsPanel(ClusterBrowser.SERVICE_LABEL_WIDTH + ClusterBrowser.SERVICE_FIELD_WIDTH + 4)); newPanel.add(new JScrollPane(mainPanel)); /* if id textfield was changed and this id is not used, * enable apply button */ infoPanel = newPanel; infoPanelDone(); return infoPanel; }
From source file:picocash.components.HeaderPanel.java
private void init() { setLayout(new MigLayout("fill")); setBackgroundPainter(this); final JXLabel picocashLabel = createLabel(PICOCASH, picocashFont); final JMenu accountLabel = createMenu(ACCOUNT); accountLabel.add(getAction("newAccount")); accountLabel.add(getAction("editAccount")); accountLabel.add(getAction("deleteAccount")); final JMenu transactionLabel = createMenu(TRANSACTION); transactionLabel.add(getAction("newTransaction")); transactionLabel.add(getAction("editTransaction")); transactionLabel.add(getAction("deleteTransaction")); final JMenu settingsLabel = createMenu(SETTINGS); settingsLabel.add(getAction("managePayees")); settingsLabel.add(getAction("manageCategories")); settingsLabel.add(new Separator()); settingsLabel.add(getAction("importAll")); settingsLabel.add(getAction("exportAll")); JMenuBar menuBar = new JMenuBar(); menuBar.setBackground(new Color(0, 0, 0, 0)); menuBar.add(accountLabel);//from w w w . j a va2s .com menuBar.add(transactionLabel); menuBar.add(settingsLabel); final JXButton closeButton = new JXButton(getAction("quit")); closeButton.setBackgroundPainter(new MattePainter<JXButton>(TRANSPARENT)); closeButton.setText(null); closeButton.setIcon(PicocashIcons.getSystemIcon("close")); closeButton.setFocusable(false); final JXButton minimizeButton = new JXButton(getAction("minimize")); minimizeButton.setBackgroundPainter(new MattePainter<JXButton>(TRANSPARENT)); minimizeButton.setIcon(PicocashIcons.getSystemIcon("minimize")); minimizeButton.setText(null); minimizeButton.setFocusable(false); final JXButton maximizeButton = new JXButton(getAction("maximize")); maximizeButton.setBackgroundPainter(new MattePainter<JXButton>(TRANSPARENT)); maximizeButton.setIcon(PicocashIcons.getSystemIcon("maximize")); maximizeButton.setText(null); maximizeButton.setFocusable(false); add(picocashLabel, "dock west, gapleft 10!"); add(menuBar, ""); add(minimizeButton, "gapleft push, split 3, w 12!, h 12!, top, gaptop 3!"); add(maximizeButton, "w 12!, h 12!, top right, gaptop 3!"); add(closeButton, " w 12!, h 12!, top right, gapright 10!, gaptop 3!"); }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
public OpenBSTGUI() { instance = this; UIManager.put("OptionPane.errorIcon", new ImageIcon(Icons.getImage("Cancel", 48))); UIManager.put("OptionPane.informationIcon", new ImageIcon(Icons.getImage("About", 48))); UIManager.put("OptionPane.questionIcon", new ImageIcon(Icons.getImage("Rename", 48))); UIManager.put("OptionPane.warningIcon", new ImageIcon(Icons.getImage("Error", 48))); BorderLayout borderLayout = new BorderLayout(); borderLayout.setVgap(4);/* w w w . j a v a 2 s . c om*/ getContentPane().setLayout(borderLayout); setIconImage(Icons.getImage("Logo", 48)); setTitle("OpenBST " + OpenBST.VERSION); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { boolean cancelled = false; int i = 0; for (Component c : container.getComponents()) { if (c instanceof StoryPanel) { i++; } else if (c instanceof StoryEditor) { container.setSelectedComponent(c); if (((StoryEditor) c).askClose()) { continue; } else { cancelled = true; break; } } } if (!cancelled) { if (i > 0) { int j = Messagers.showConfirm(OpenBSTGUI.this, "You are about to close " + i + " file(s). Are you sure you wish to exit OpenBST?", Messagers.OPTIONS_YES_NO, Messagers.TYPE_WARNING, "Closing OpenBST"); if (j != Messagers.OPTION_YES) cancelled = true; } if (!cancelled) System.exit(0); } } }); JMenuBar jmb = new JMenuBar(); jmb.setBackground(OPENBST_BLUE); jmb.add(Box.createHorizontalGlue()); jmb.add(createShortMenu()); jmb.add(Box.createHorizontalGlue()); this.setJMenuBar(jmb); addDarkModeCallback(b -> { jmb.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE); }); container = new JTabbedPane(); container.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); container.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isMiddleMouseButton(e)) { final int i = container.indexAtLocation(e.getX(), e.getY()); System.out.println(i); if (i > -1) { Component c = container.getComponentAt(i); if (c instanceof StoryPanel) { container.setSelectedComponent(c); ((StoryPanel) c).askClose(); } else if (c instanceof StoryEditor) { container.setSelectedComponent(c); ((StoryEditor) c).askClose(); } } } } }); getContentPane().add(container, BorderLayout.CENTER); final JBackgroundPanel welcomeContentPanel = new JBackgroundPanel(Icons.getRandomBackground(), Image.SCALE_FAST); background = welcomeContentPanel; welcomeContentPanel.setLayout(new MigLayout("hidemode 2", "[grow,center]", "[][grow][]")); container.add(welcomeContentPanel); container.setTitleAt(0, Lang.get("welcome")); bannersPanel = new JPanel(new MigLayout("hidemode 2, gap 0px, fill, wrap 1, ins 0")); bannersPanel.setBackground(new Color(0, 0, 0, 0)); welcomeContentPanel.add(bannersPanel, "cell 0 0,grow"); if (OpenBST.VERSION.endsWith("u")) { JButton btnReportBugs = new JButton(Lang.get("welcome.reportbugs")); btnReportBugs.addActionListener(e -> { VisualsUtils.browse("https://github.com/utybo/BST/issues"); }); bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.YELLOW, Lang.get("welcome.ontheedge"), btnReportBugs, false), "grow"); } else if (OpenBST.VERSION.contains("SNAPSHOT")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Experiment", 32)), Color.ORANGE, Lang.get("welcome.snapshot"), null, false), "grow"); } if (System.getProperty("java.specification.version").equals("9")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)), new Color(255, 50, 50), Lang.get("welcome.java9warning"), null, false), "grow"); } if (System.getProperty("java.specification.version").equals("10")) { bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Attention", 32)), new Color(255, 50, 50), Lang.get("welcome.java10warning"), null, false), "grow"); } JButton btnJoinDiscord = new JButton(Lang.get("openbst.discordjoin")); btnJoinDiscord.addActionListener(e -> { VisualsUtils.browse("https://discord.gg/6SVDCMM"); }); bannersPanel.add(new JBannerPanel(new ImageIcon(Icons.getImage("Discord", 48)), DISCORD_COLOR, Lang.get("openbst.discord"), btnJoinDiscord, true), "grow"); JPanel panel = new JPanel(); panel.setBackground(new Color(0, 0, 0, 0)); welcomeContentPanel.add(panel, "flowx,cell 0 1,growx,aligny center"); panel.setLayout(new MigLayout("", "[40%][][][][60%,growprio 50]", "[][grow]")); final JLabel lblOpenbst = new JLabel(new ImageIcon(Icons.getImage("FullLogo", 48))); addDarkModeCallback(b -> lblOpenbst .setIcon(new ImageIcon(b ? Icons.getImage("FullLogoWhite", 48) : Icons.getImage("FullLogo", 48)))); panel.add(lblOpenbst, "flowx,cell 0 0 1 2,alignx trailing,aligny center"); JSeparator separator = new JSeparator(); separator.setOrientation(SwingConstants.VERTICAL); panel.add(separator, "cell 2 0 1 2,growy"); final JLabel lblWelcomeToOpenbst = new JLabel("<html>" + Lang.get("welcome.intro")); lblWelcomeToOpenbst.setMaximumSize(new Dimension(350, 999999)); panel.add(lblWelcomeToOpenbst, "cell 4 0"); Component horizontalStrut = Box.createHorizontalStrut(10); panel.add(horizontalStrut, "cell 1 1"); Component horizontalStrut_1 = Box.createHorizontalStrut(10); panel.add(horizontalStrut_1, "cell 3 1"); final JButton btnOpenAFile = new JButton(Lang.get("welcome.open")); panel.add(btnOpenAFile, "flowx,cell 4 1"); btnOpenAFile.setIcon(new ImageIcon(Icons.getImage("Open", 40))); btnOpenAFile.addActionListener(e -> { openStory(VisualsUtils.askForFile(this, Lang.get("file.title"))); }); final JButton btnOpenEditor = new JButton(Lang.get("welcome.openeditor")); panel.add(btnOpenEditor, "cell 4 1"); btnOpenEditor.setIcon(new ImageIcon(Icons.getImage("Edit Property", 40))); btnOpenEditor.addActionListener(e -> { openEditor(VisualsUtils.askForFile(this, Lang.get("file.title"))); }); JButton btnChangeBackground = new JButton(Lang.get("welcome.changebackground"), new ImageIcon(Icons.getImage("Change Theme", 16))); btnChangeBackground.addActionListener(e -> { BufferedImage prev = background.getImage(); BufferedImage next; do { next = Icons.getRandomBackground(); } while (prev == next); background.setImage(next); }); welcomeContentPanel.add(btnChangeBackground, "flowx,cell 0 2,alignx left"); JButton btnWelcomepixabay = new JButton(Lang.get("welcome.pixabay"), new ImageIcon(Icons.getImage("External Link", 16))); btnWelcomepixabay.addActionListener(e -> { VisualsUtils.browse("https://pixabay.com"); }); welcomeContentPanel.add(btnWelcomepixabay, "cell 0 2"); JLabel creds = new JLabel(Lang.get("welcome.credits")); creds.setEnabled(false); welcomeContentPanel.add(creds, "cell 0 2, gapbefore 10px"); setSize((int) (830 * Icons.getScale()), (int) (480 * Icons.getScale())); setLocationRelativeTo(null); }