List of usage examples for java.awt GridBagLayout setConstraints
public void setConstraints(Component comp, GridBagConstraints constraints)
From source file:TalkServerThread.java
public void init() { //Get the address of the host we came from. host = getCodeBase().getHost();//from w ww . ja va 2 s .c om //Set up the UI. GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridBag); message = new TextField(""); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; gridBag.setConstraints(message, c); message.addActionListener(this); add(message); display = new TextArea(10, 40); display.setEditable(false); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; gridBag.setConstraints(display, c); add(display); Label l = new Label("Enter the port (on host " + host + ") to send the request to:", Label.RIGHT); c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.weightx = 0.0; c.weighty = 0.0; gridBag.setConstraints(l, c); add(l); portField = new TextField(6); c.fill = GridBagConstraints.NONE; gridBag.setConstraints(portField, c); portField.addActionListener(this); add(portField); button = new Button("Connect"); gridBag.setConstraints(button, c); button.addActionListener(this); add(button); newline = System.getProperty("line.separator"); }
From source file:com.wet.wired.jsr.player.JPlayer.java
private JPanel createSliderLayout() { slider.setEnabled(false);/* w w w. j a v a2 s. co m*/ JPanel sliderPanel = new JPanel(); sliderPanel.setPreferredSize(close.getSize()); // use default size of // button GridBagLayout gbl = new GridBagLayout(); sliderPanel.setLayout(gbl); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(2, 2, 2, 2); gbc.gridx = 0; gbc.gridy = 0; gbc.gridheight = 1; gbc.weightx = 1.0; gbl.setConstraints(slider, gbc); sliderPanel.add(slider); return sliderPanel; }
From source file:net.sf.jabref.gui.preftabs.PreviewPrefsTab.java
public PreviewPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; GridBagLayout layout = new GridBagLayout(); firstPanel.setLayout(layout);/* ww w .j a v a2 s .c o m*/ secondPanel.setLayout(layout); setLayout(layout); JLabel lab = new JLabel(Localization.lang("Preview") + " 1"); GridBagConstraints layoutConstraints = new GridBagConstraints(); layoutConstraints.anchor = GridBagConstraints.WEST; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.weightx = 1; layoutConstraints.weighty = 0; layoutConstraints.insets = new Insets(2, 2, 2, 2); layout.setConstraints(lab, layoutConstraints); layoutConstraints.weighty = 1; layout.setConstraints(firstScrollPane, layoutConstraints); firstPanel.add(firstScrollPane); layoutConstraints.weighty = 0; layoutConstraints.gridwidth = 1; layoutConstraints.weightx = 0; layoutConstraints.fill = GridBagConstraints.NONE; layoutConstraints.anchor = GridBagConstraints.WEST; layout.setConstraints(testButton, layoutConstraints); firstPanel.add(testButton); layout.setConstraints(defaultButton, layoutConstraints); firstPanel.add(defaultButton); layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; JPanel newPan = new JPanel(); layoutConstraints.weightx = 1; layout.setConstraints(newPan, layoutConstraints); firstPanel.add(newPan); lab = new JLabel(Localization.lang("Preview") + " 2"); layout.setConstraints(lab, layoutConstraints); // p2.add(lab); layoutConstraints.weighty = 1; layoutConstraints.fill = GridBagConstraints.BOTH; layout.setConstraints(secondScrollPane, layoutConstraints); secondPanel.add(secondScrollPane); layoutConstraints.weighty = 0; layoutConstraints.weightx = 0; layoutConstraints.fill = GridBagConstraints.NONE; layoutConstraints.gridwidth = 1; layout.setConstraints(testButton2, layoutConstraints); secondPanel.add(testButton2); layout.setConstraints(defaultButton2, layoutConstraints); secondPanel.add(defaultButton2); layoutConstraints.gridwidth = 1; newPan = new JPanel(); layoutConstraints.weightx = 1; layout.setConstraints(newPan, layoutConstraints); secondPanel.add(newPan); layoutConstraints.weightx = 1; layoutConstraints.weighty = 0; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; lab = new JLabel(Localization.lang("Preview") + " 1"); layout.setConstraints(lab, layoutConstraints); add(lab); layoutConstraints.weighty = 1; layout.setConstraints(firstPanel, layoutConstraints); add(firstPanel); lab = new JLabel(Localization.lang("Preview") + " 2"); layoutConstraints.weighty = 0; JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL); layout.setConstraints(sep, layoutConstraints); add(sep); layout.setConstraints(lab, layoutConstraints); add(lab); layoutConstraints.weighty = 1; layout.setConstraints(secondPanel, layoutConstraints); add(secondPanel); layoutConstraints.weighty = 0; defaultButton.addActionListener(e -> { String tmp = layout1.getText().replace("\n", "__NEWLINE__"); PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_0); layout1.setText( PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_0).replace("__NEWLINE__", "\n")); PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_0, tmp); }); defaultButton2.addActionListener(e -> { String tmp = layout2.getText().replace("\n", "__NEWLINE__"); PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_1); layout2.setText( PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_1).replace("__NEWLINE__", "\n")); PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_1, tmp); }); testButton.addActionListener(e -> { PreviewPrefsTab.getTestEntry(); try { PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout1.getText()); testPanel.setPreferredSize(new Dimension(800, 350)); JOptionPane.showMessageDialog(null, testPanel, Localization.lang("Preview"), JOptionPane.PLAIN_MESSAGE); } catch (StringIndexOutOfBoundsException ex) { LOGGER.warn("Parsing error.", ex); JOptionPane.showMessageDialog(null, Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(), Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE); } }); testButton2.addActionListener(e -> { PreviewPrefsTab.getTestEntry(); try { PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout2.getText()); testPanel.setPreferredSize(new Dimension(800, 350)); JOptionPane.showMessageDialog(null, new JScrollPane(testPanel), Localization.lang("Preview"), JOptionPane.PLAIN_MESSAGE); } catch (StringIndexOutOfBoundsException ex) { LOGGER.warn("Parsing error.", ex); JOptionPane.showMessageDialog(null, Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(), Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE); } }); }
From source file:com.choicemaker.cm.modelmaker.gui.panels.StatisticsHistogramPanel.java
private void layoutPanel() { GridBagLayout layout = new GridBagLayout(); setLayout(layout);/*from ww w.j a va 2 s. com*/ GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 10, 5, 10); //Row 0.......................................................... //histo c.gridy = 0; c.gridx = 0; c.gridwidth = 5; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; add(histoPanel, c); //Row 1.......................................................... //binWidthLabel c.gridy = 1; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.EAST; layout.setConstraints(binWidthLabel, c); add(binWidthLabel); //binWidthField c.gridx = 2; c.ipadx = 10; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; layout.setConstraints(binWidthField, c); add(binWidthField); }
From source file:com.intuit.tank.tools.debugger.FindReplaceDialog.java
/** * Constructs a new find dialog according to the specified type of dialog requested. The dialog can be either a FIND * dialog, either a REPLACE dialog. In both cases, components displayed remain the sames, but the ones specific to * replace feature are grayed out./*from ww w .j av a 2 s.com*/ * * @param parent * The window holder * @param type * The type of the dialog: FindReplace.FIND or FindReplace.REPLACE * @param modal * Displays dialog as a modal window if true */ public FindReplaceDialog(AgentDebuggerFrame parent, DialogType type) { super(parent, type == DialogType.REPLACE ? "Replace" : "Find", true); this.parent = parent; cbSearch = new JComboBox(); cbSearch.setEditable(true); cbReplace = new JComboBox(); cbReplace.setEditable(true); KeyHandler handler = new KeyHandler(); tfSearchEditor = (JTextField) cbSearch.getEditor().getEditorComponent(); tfSearchEditor.addKeyListener(handler); tfReplaceEditor = (JTextField) cbReplace.getEditor().getEditorComponent(); tfReplaceEditor.addKeyListener(handler); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); getContentPane().setLayout(gridbag); ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); int gridX = 0; int gridY = 0; JLabel findLabel = new JLabel("Find"); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(findLabel, constraints); getContentPane().add(findLabel); gridX++; buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(cbSearch, constraints); getContentPane().add(cbSearch); gridX++; btnFind = new JButton("Find"); btnFind.setToolTipText("Find text in scripts"); btnFind.setMnemonic('F'); btnFind.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnFind, constraints); getContentPane().add(btnFind); getRootPane().setDefaultButton(btnFind); gridX++; btnCancel = new JButton("Cancel"); btnCancel.setMnemonic('C'); btnCancel.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnCancel, constraints); getContentPane().add(btnCancel); gridY++; gridX = 0; if (type == DialogType.REPLACE) { JLabel replaceLabel = new JLabel("Replace"); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(replaceLabel, constraints); getContentPane().add(replaceLabel); gridX++; buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(cbReplace, constraints); getContentPane().add(cbReplace); gridX++; btnReplace = new JButton("Replace"); btnReplace.setToolTipText("REplace in script"); btnReplace.setMnemonic('R'); btnReplace.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnReplace, constraints); getContentPane().add(btnReplace); gridX++; btnReplaceAll = new JButton("Replace All"); btnReplaceAll.addActionListener(this); buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(btnReplaceAll, constraints); getContentPane().add(btnReplaceAll); btnReplace.addKeyListener(handler); btnReplaceAll.addKeyListener(handler); gridY++; gridX = 0; } TitledBorder border = new TitledBorder("Options"); JPanel panel = new JPanel(new GridLayout(1, 4)); panel.setBorder(border); checkboxWrap = new JCheckBox("Wrap Search"); panel.add(checkboxWrap); checkboxMatchCase = new JCheckBox("Case sensitive"); panel.add(checkboxMatchCase); checkboxRegexp = new JCheckBox("Regular expressions"); panel.add(checkboxRegexp); buildConstraints(constraints, gridX, gridY, 4, 1, 100, 100); constraints.anchor = GridBagConstraints.WEST; gridbag.setConstraints(panel, constraints); getContentPane().add(panel); FontMetrics fm = getFontMetrics(getFont()); cbSearch.setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbSearch.getPreferredSize().height)); cbReplace .setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbReplace.getPreferredSize().height)); pack(); // setResizable(false); WindowUtil.centerOnParent(this); // patch by MJB 8/1/2002 btnFind.addKeyListener(handler); btnCancel.addKeyListener(handler); checkboxMatchCase.addKeyListener(handler); checkboxRegexp.addKeyListener(handler); }
From source file:DiningPhilosophers.java
public void init() { imgs[HUNGRYDUKE] = new ImageIcon(getURL("images/hungryduke.gif")); imgs[RIGHTSPOONDUKE] = new ImageIcon(getURL("images/rightspoonduke.gif")); imgs[BOTHSPOONSDUKE] = new ImageIcon(getURL("images/bothspoonsduke.gif")); width = imgs[HUNGRYDUKE].getIconWidth() + (int) (MARGIN * 2.0); height = imgs[HUNGRYDUKE].getIconHeight() + (int) (MARGIN * 2.0); spacing = width + MARGIN;//from www . j a va2s. c o m GridBagLayout gridBag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); JPanel contentPane = new JPanel(); contentPane.setLayout(gridBag); philosopherArea = new JPanel(null); philosopherArea.setBackground(Color.white); Dimension preferredSize = createPhilosophersAndChopsticks(); philosopherArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLoweredBevelBorder(), BorderFactory.createEmptyBorder(5, 5, 5, 5))); philosopherArea.setPreferredSize(preferredSize); c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; c.gridwidth = GridBagConstraints.REMAINDER; //end row gridBag.setConstraints(philosopherArea, c); contentPane.add(philosopherArea); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.weighty = 0.0; gridBag.setConstraints(stopStartButton, c); contentPane.add(stopStartButton); c.gridwidth = GridBagConstraints.RELATIVE; //don't end row c.weightx = 1.0; c.weighty = 0.0; gridBag.setConstraints(grabDelaySlider, c); contentPane.add(grabDelaySlider); c.weightx = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; //end row gridBag.setConstraints(label, c); contentPane.add(label); contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); stopStartButton.addActionListener(this); grabDelaySlider.addChangeListener(this); }
From source file:net.vanosten.dings.swing.SummaryView.java
private void initializeChartPropertiesPanel() { chartPropertiesP = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); chartPropertiesP.setLayout(gbl);//w w w. j av a 2s. co m TitledBorder title; title = BorderFactory.createTitledBorder("Chart Properties"); chartPropertiesP.setBorder(title); JLabel typeL = new JLabel("Chart Type:"); typeL.setDisplayedMnemonic("C".charAt(0)); typeL.setLabelFor(chartTypeCB); JLabel emptyL = new JLabel(); Insets vghg = new Insets(DingsSwingConstants.SP_V_G, DingsSwingConstants.SP_H_G, 0, 0); //----type gbc.gridwidth = 1; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.LINE_END; gbc.insets = vghg; gbl.setConstraints(typeL, gbc); chartPropertiesP.add(typeL); //---- gbc.gridx = 1; gbc.anchor = GridBagConstraints.LINE_START; gbl.setConstraints(chartTypeCB, gbc); chartPropertiesP.add(chartTypeCB); //---- gbc.gridx = 2; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbl.setConstraints(emptyL, gbc); chartPropertiesP.add(emptyL); //----chosen gbc.gridx = 1; gbc.gridy = 1; gbc.weightx = 0.0; gbc.fill = GridBagConstraints.NONE; gbl.setConstraints(chosenCB, gbc); chartPropertiesP.add(chosenCB); }
From source file:mazewar.Mazewar.java
/** * The place where all the pieces are put together. *///from www .j av a 2s .co m public Mazewar(String zkServer, int zkPort, int port, String name, String game, boolean robot) { super("ECE419 Mazewar"); consolePrintLn("ECE419 Mazewar started!"); /* Set up parent */ ZK_PARENT += game; // Throw up a dialog to get the GUIClient name. if (name != null) { clientId = name; } else { clientId = JOptionPane.showInputDialog("Enter your name"); } if ((clientId == null) || (clientId.length() == 0)) { Mazewar.quit(); } /* Connect to ZooKeeper and get sequencer details */ List<ClientNode> nodeList = null; try { zkWatcher = new ZkWatcher(); zkConnected = new CountDownLatch(1); zooKeeper = new ZooKeeper(zkServer + ":" + zkPort, ZK_TIMEOUT, new Watcher() { @Override public void process(WatchedEvent event) { /* Release Lock if ZooKeeper is connected */ if (event.getState() == SyncConnected) { zkConnected.countDown(); } else { System.err.println("Could not connect to ZooKeeper!"); System.exit(0); } } }); zkConnected.await(); /* Successfully connected, now create our node on ZooKeeper */ zooKeeper.create(Joiner.on('/').join(ZK_PARENT, clientId), Joiner.on(':').join(InetAddress.getLocalHost().getHostAddress(), port).getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL); /* Get Seed from Parent */ mazeSeed = Long.parseLong(new String(zooKeeper.getData(ZK_PARENT, false, null))); /* Initialize Sequence Number */ sequenceNumber = new AtomicInteger(zooKeeper.exists(ZK_PARENT, false).getVersion()); /* Get list of nodes */ nodeList = ClientNode.sortList(zooKeeper.getChildren(ZK_PARENT, false)); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // Create the maze maze = new MazeImpl(new Point(mazeWidth, mazeHeight), mazeSeed); assert (maze != null); // Have the ScoreTableModel listen to the maze to find // out how to adjust scores. ScoreTableModel scoreModel = new ScoreTableModel(); assert (scoreModel != null); maze.addMazeListener(scoreModel); /* Initialize packet queue */ packetQueue = new ArrayBlockingQueue<MazePacket>(QUEUE_SIZE); sequencedQueue = new PriorityBlockingQueue<MazePacket>(QUEUE_SIZE, new Comparator<MazePacket>() { @Override public int compare(MazePacket o1, MazePacket o2) { return o1.sequenceNumber.compareTo(o2.sequenceNumber); } }); /* Inject Event Bus into Client */ Client.setEventBus(eventBus); /* Initialize ZMQ Context */ context = ZMQ.context(2); /* Set up publisher */ publisher = context.socket(ZMQ.PUB); publisher.bind("tcp://*:" + port); System.out.println("ZeroMQ Publisher Bound On: " + port); try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } /* Set up subscriber */ subscriber = context.socket(ZMQ.SUB); subscriber.subscribe(ArrayUtils.EMPTY_BYTE_ARRAY); clients = new ConcurrentHashMap<String, Client>(); try { for (ClientNode client : nodeList) { if (client.getName().equals(clientId)) { clientPath = ZK_PARENT + "/" + client.getPath(); guiClient = robot ? new RobotClient(clientId) : new GUIClient(clientId); clients.put(clientId, guiClient); maze.addClient(guiClient); eventBus.register(guiClient); subscriber.connect("tcp://" + new String(zooKeeper.getData(clientPath, false, null))); } else { addRemoteClient(client); } } } catch (Exception e) { e.printStackTrace(); } checkNotNull(guiClient, "Should have received our clientId in CLIENTS list!"); // Create the GUIClient and connect it to the KeyListener queue this.addKeyListener(guiClient); this.isRobot = robot; // Use braces to force constructors not to be called at the beginning of the // constructor. /*{ maze.addClient(new RobotClient("Norby")); maze.addClient(new RobotClient("Robbie")); maze.addClient(new RobotClient("Clango")); maze.addClient(new RobotClient("Marvin")); }*/ // Create the panel that will display the maze. overheadPanel = new OverheadMazePanel(maze, guiClient); assert (overheadPanel != null); maze.addMazeListener(overheadPanel); // Don't allow editing the console from the GUI console.setEditable(false); console.setFocusable(false); console.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder())); // Allow the console to scroll by putting it in a scrollpane JScrollPane consoleScrollPane = new JScrollPane(console); assert (consoleScrollPane != null); consoleScrollPane .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Console")); // Create the score table scoreTable = new JTable(scoreModel); assert (scoreTable != null); scoreTable.setFocusable(false); scoreTable.setRowSelectionAllowed(false); // Allow the score table to scroll too. JScrollPane scoreScrollPane = new JScrollPane(scoreTable); assert (scoreScrollPane != null); scoreScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Scores")); // Create the layout manager GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); getContentPane().setLayout(layout); // Define the constraints on the components. c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 3.0; c.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(overheadPanel, c); c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 2.0; c.weighty = 1.0; layout.setConstraints(consoleScrollPane, c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; layout.setConstraints(scoreScrollPane, c); // Add the components getContentPane().add(overheadPanel); getContentPane().add(consoleScrollPane); getContentPane().add(scoreScrollPane); // Pack everything neatly. pack(); // Let the magic begin. setVisible(true); overheadPanel.repaint(); this.requestFocusInWindow(); }
From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java
/** * Adds a component to a container, using the specified gridbag-layout and * the supplied parameters. <br>//from www .j a v a2s . com * <br> * This method is simply used to ged rid of thousands of lines of code, * which inevitably rise when layouts such as the gridbag-layout is being * used. * * @param layout * The layout to be used. * @param container * The {@link Container}, to which the component will be added. * @param component * An AWT {@link Component}, that will be added to the container. * @param fill * A constant describing the fill behaviour (see * {@link GridBagConstraints}). Can be <code>null</code>, if no * filling wants to be specified. * @param anchor * A constant describing the anchor of the element in its parent * container (see {@link GridBagConstraints}). Can be * <code>null</code>, if no specification is needed. * @param gridX * The relative grid-X coordinate. * @param gridY * The relative grid-Y coordinate. * @param width * The relative width of the component. * @param height * The relative height of the component. * @param weightX * A value for the horizontal weight. * @param weightY * A value for the vertical weight. * @param insets * Insets of the component. Can be <code>null</code>. */ private static void addComponent(GridBagLayout layout, Container container, Component component, Integer fill, Integer anchor, Insets insets, int gridX, int gridY, int width, int height, double weightX, double weightY, int ipadX, int ipadY) { container.setLayout(layout); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = gridX; constraints.gridy = gridY; constraints.gridwidth = width; constraints.gridheight = height; constraints.weightx = weightX; constraints.weighty = weightY; constraints.ipadx = ipadX; constraints.ipady = ipadY; if (fill != null) { constraints.fill = fill; } if (insets != null) { constraints.insets = insets; } if (anchor != null) { constraints.anchor = anchor; } layout.setConstraints(component, constraints); container.add(component); }
From source file:gov.loc.repository.bagger.ui.SaveBagFrame.java
private JPanel createComponents() { Border border = new EmptyBorder(5, 5, 5, 5); TitlePane titlePane = new TitlePane(); initStandardCommands();//from www .j a v a2s . c o m JPanel pageControl = new JPanel(new BorderLayout()); JPanel titlePaneContainer = new JPanel(new BorderLayout()); titlePane.setTitle(bagView.getPropertyMessage("SaveBagFrame.title")); titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Define the Bag settings"))); titlePaneContainer.add(titlePane.getControl()); titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH); pageControl.add(titlePaneContainer, BorderLayout.NORTH); JPanel contentPane = new JPanel(); // TODO: Add bag name field // TODO: Add save name file selection button JLabel location = new JLabel("Save in:"); browseButton = new JButton(getMessage("bag.button.browse")); browseButton.addActionListener(new SaveBagAsHandler()); browseButton.setEnabled(true); browseButton.setToolTipText(getMessage("bag.button.browse.help")); String fileName = ""; DefaultBag bag = bagView.getBag(); if (bag != null) { fileName = bag.getName(); } bagNameField = new JTextField(fileName); bagNameField.setCaretPosition(fileName.length()); bagNameField.setEditable(false); bagNameField.setEnabled(false); // Holey bag control JLabel holeyLabel = new JLabel(bagView.getPropertyMessage("bag.label.isholey")); holeyLabel.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); holeyCheckbox = new JCheckBox(bagView.getPropertyMessage("bag.checkbox.isholey")); holeyCheckbox.setBorder(border); holeyCheckbox.setSelected(bag.isHoley()); holeyCheckbox.addActionListener(new HoleyBagHandler()); holeyCheckbox.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label")); urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description")); urlLabel.setEnabled(bag.isHoley()); urlField = new JTextField(""); try { urlField.setText(bag.getFetch().getBaseURL()); } catch (Exception e) { log.error("fetch baseURL: " + e.getMessage()); } urlField.setEnabled(false); // TODO: Add format label JLabel serializeLabel; serializeLabel = new JLabel(getMessage("bag.label.ispackage")); serializeLabel.setToolTipText(getMessage("bag.serializetype.help")); // TODO: Add format selection panel noneButton = new JRadioButton(getMessage("bag.serializetype.none")); noneButton.setEnabled(true); AbstractAction serializeListener = new SerializeBagHandler(); noneButton.addActionListener(serializeListener); noneButton.setToolTipText(getMessage("bag.serializetype.none.help")); zipButton = new JRadioButton(getMessage("bag.serializetype.zip")); zipButton.setEnabled(true); zipButton.addActionListener(serializeListener); zipButton.setToolTipText(getMessage("bag.serializetype.zip.help")); /* tarButton = new JRadioButton(getMessage("bag.serializetype.tar")); tarButton.setEnabled(true); tarButton.addActionListener(serializeListener); tarButton.setToolTipText(getMessage("bag.serializetype.tar.help")); tarGzButton = new JRadioButton(getMessage("bag.serializetype.targz")); tarGzButton.setEnabled(true); tarGzButton.addActionListener(serializeListener); tarGzButton.setToolTipText(getMessage("bag.serializetype.targz.help")); tarBz2Button = new JRadioButton(getMessage("bag.serializetype.tarbz2")); tarBz2Button.setEnabled(true); tarBz2Button.addActionListener(serializeListener); tarBz2Button.setToolTipText(getMessage("bag.serializetype.tarbz2.help")); */ short mode = bag.getSerialMode(); if (mode == DefaultBag.NO_MODE) { this.noneButton.setEnabled(true); } else if (mode == DefaultBag.ZIP_MODE) { this.zipButton.setEnabled(true); } /*else if (mode == DefaultBag.TAR_MODE) { this.tarButton.setEnabled(true); } else if (mode == DefaultBag.TAR_GZ_MODE) { this.tarGzButton.setEnabled(true); } else if (mode == DefaultBag.TAR_BZ2_MODE) { this.tarBz2Button.setEnabled(true); } */else { this.noneButton.setEnabled(true); } ButtonGroup serializeGroup = new ButtonGroup(); serializeGroup.add(noneButton); serializeGroup.add(zipButton); //serializeGroup.add(tarButton); //serializeGroup.add(tarGzButton); //serializeGroup.add(tarBz2Button); serializeGroupPanel = new JPanel(new FlowLayout()); serializeGroupPanel.add(serializeLabel); serializeGroupPanel.add(noneButton); serializeGroupPanel.add(zipButton); //serializeGroupPanel.add(tarButton); //serializeGroupPanel.add(tarGzButton); //serializeGroupPanel.add(tarBz2Button); serializeGroupPanel.setBorder(border); serializeGroupPanel.setEnabled(true); serializeGroupPanel.setToolTipText(bagView.getPropertyMessage("bag.serializetype.help")); JLabel tagLabel = new JLabel(getMessage("bag.label.istag")); tagLabel.setToolTipText(getMessage("bag.label.istag.help")); isTagCheckbox = new JCheckBox(); isTagCheckbox.setBorder(border); isTagCheckbox.setSelected(bag.isBuildTagManifest()); isTagCheckbox.addActionListener(new TagManifestHandler()); isTagCheckbox.setToolTipText(getMessage("bag.checkbox.istag.help")); JLabel tagAlgorithmLabel = new JLabel(getMessage("bag.label.tagalgorithm")); tagAlgorithmLabel.setToolTipText(getMessage("bag.label.tagalgorithm.help")); ArrayList<String> listModel = new ArrayList<String>(); for (Algorithm algorithm : Algorithm.values()) { listModel.add(algorithm.bagItAlgorithm); } tagAlgorithmList = new JComboBox(listModel.toArray()); tagAlgorithmList.setName(getMessage("bag.tagalgorithmlist")); tagAlgorithmList.setSelectedItem(bag.getTagManifestAlgorithm()); tagAlgorithmList.addActionListener(new TagAlgorithmListHandler()); tagAlgorithmList.setToolTipText(getMessage("bag.tagalgorithmlist.help")); JLabel payloadLabel = new JLabel(getMessage("bag.label.ispayload")); payloadLabel.setToolTipText(getMessage("bag.ispayload.help")); isPayloadCheckbox = new JCheckBox(); isPayloadCheckbox.setBorder(border); isPayloadCheckbox.setSelected(bag.isBuildPayloadManifest()); isPayloadCheckbox.addActionListener(new PayloadManifestHandler()); isPayloadCheckbox.setToolTipText(getMessage("bag.ispayload.help")); JLabel payAlgorithmLabel = new JLabel(bagView.getPropertyMessage("bag.label.payalgorithm")); payAlgorithmLabel.setToolTipText(getMessage("bag.payalgorithm.help")); payAlgorithmList = new JComboBox(listModel.toArray()); payAlgorithmList.setName(getMessage("bag.payalgorithmlist")); payAlgorithmList.setSelectedItem(bag.getPayloadManifestAlgorithm()); payAlgorithmList.addActionListener(new PayAlgorithmListHandler()); payAlgorithmList.setToolTipText(getMessage("bag.payalgorithmlist.help")); GridBagLayout layout = new GridBagLayout(); GridBagConstraints glbc = new GridBagConstraints(); JPanel panel = new JPanel(layout); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); int row = 0; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(location, glbc); panel.add(location); buildConstraints(glbc, 2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); glbc.ipadx = 5; layout.setConstraints(browseButton, glbc); glbc.ipadx = 0; panel.add(browseButton); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc.ipadx = 5; layout.setConstraints(bagNameField, glbc); glbc.ipadx = 0; panel.add(bagNameField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(holeyLabel, glbc); panel.add(holeyLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.WEST, GridBagConstraints.WEST); layout.setConstraints(holeyCheckbox, glbc); panel.add(holeyCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(urlLabel, glbc); panel.add(urlLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(urlField, glbc); panel.add(urlField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(serializeLabel, glbc); panel.add(serializeLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); layout.setConstraints(serializeGroupPanel, glbc); panel.add(serializeGroupPanel); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagLabel, glbc); panel.add(tagLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isTagCheckbox, glbc); panel.add(isTagCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagAlgorithmLabel, glbc); panel.add(tagAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(tagAlgorithmList, glbc); panel.add(tagAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payloadLabel, glbc); panel.add(payloadLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isPayloadCheckbox, glbc); panel.add(isPayloadCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payAlgorithmLabel, glbc); panel.add(payAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(payAlgorithmList, glbc); panel.add(payAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); GuiStandardUtils.attachDialogBorder(contentPane); pageControl.add(panel); JComponent buttonBar = createButtonBar(); pageControl.add(buttonBar, BorderLayout.SOUTH); this.pack(); return pageControl; }