📄 mgrsattributespanel.java
字号:
private void onLayerPropertyChanged(PropertyChangeEvent event) { if (event != null) { if (!this.ignoreLayerEvents) { updateComponents(); } } } private void updateComponents() { this.ignoreUIEvents = true; try { if (this.layer != null) { this.maxResolutionComboBox.setSelectedItem(layer.getMaximumGraticuleResolution()); } for (Map.Entry<String, Component> entry : this.graticuleAttribPanelMap.entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { if (entry.getValue() instanceof GraticuleAttributesPanel) { updatePanelState((GraticuleAttributesPanel) entry.getValue(), entry.getKey()); } } } } finally { this.ignoreUIEvents = false; } } private void updatePanelState(GraticuleAttributesPanel panel, String graticuleType) { if (this.layer != null && panel != null && graticuleType != null) { panel.setSelectedLineColor(this.layer.getGraticuleLineColor(graticuleType)); panel.setSelectedLineWidth(this.layer.getGraticuleLineWidth(graticuleType)); panel.setSelectedLineStyle(this.layer.getGraticuleLineStyle(graticuleType)); panel.setLabelEnableSelected(this.layer.isDrawLabels(graticuleType)); panel.setSelectedLabelColor(this.layer.getLabelColor(graticuleType)); panel.setSelectedLabelFont(this.layer.getLabelFont(graticuleType)); } } private static String loadString(File file) throws IOException { String s = null; FileReader reader = null; try { reader = new FileReader(file); StringBuilder sb = new StringBuilder(); int numRead; char[] buffer = new char[2048]; while ((numRead = reader.read(buffer, 0, buffer.length)) != -1) { sb.append(buffer, 0, numRead); } s = sb.toString(); } finally { try { if (reader != null) reader.close(); } catch (Exception e) { e.printStackTrace(); } } return s; } private static void saveString(String s, File file) throws IOException { FileWriter writer = null; try { if (s != null && file != null) { writer = new FileWriter(file); writer.write(s); } } finally { try { if (writer != null) writer.close(); } catch (Exception e) { e.printStackTrace(); } } } private void makeComponents() { this.itemList = new JList(ALL_GRATICULE_TYPES); this.itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); ListCellRenderer originalRenderer = this.itemList.getCellRenderer(); this.itemList.setCellRenderer(new GraticuleTypeListRenderer(originalRenderer, null)); this.itemList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { onListSelectionChanged(event); } }); this.saveStateButton = new JButton("Save State"); this.saveStateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { onSaveStatePressed(event); } }); this.loadStateButton = new JButton("Load State"); this.loadStateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { onLoadStatePressed(event); } }); this.maxResolutionComboBox = new JComboBox(MGRS_GRATICULE_TYPES); originalRenderer = this.maxResolutionComboBox.getRenderer(); this.maxResolutionComboBox.setRenderer(new GraticuleTypeListRenderer(originalRenderer, null)); this.maxResolutionComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { onMaxResolutionChanged(event); } }); this.cardLayout = new CardLayout(); this.cardPanel = new JPanel(); this.cardPanel.setLayout(this.cardLayout); for (String type : ALL_GRATICULE_TYPES) { Component panel = makeGraticulePanel(type); this.graticuleAttribPanelMap.put(type, panel); } } private Component makeGraticulePanel(final String graticuleType) { if (graticuleType == null) { String message = Logging.getMessage("nullValue.StringIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } GraticuleAttributesPanel panel = new GraticuleAttributesPanel(); panel.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { onPanelStateChanged(event, graticuleType); } }); return panel; } private void layoutComponents() { setLayout(new BorderLayout()); //---------- Graticule Item List ----------// { Box box = Box.createVerticalBox(); box.setBorder(new EmptyBorder(30, 20, 20, 5)); JScrollPane itemScrollPane = new JScrollPane(this.itemList); itemScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(itemScrollPane); box.add(Box.createVerticalStrut(20)); JLabel label = new JLabel("Maximum Resolution"); label.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(label); this.maxResolutionComboBox.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(this.maxResolutionComboBox); box.add(Box.createVerticalStrut(20)); this.saveStateButton.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(this.saveStateButton); this.loadStateButton.setAlignmentX(Component.LEFT_ALIGNMENT); box.add(this.loadStateButton); box.add(Box.createVerticalGlue()); add(box, BorderLayout.WEST); } //---------- Graticule Card Panel ----------// { this.cardPanel.setBorder(new EmptyBorder(30, 5, 20, 20)); for (Map.Entry<String, Component> entry : this.graticuleAttribPanelMap.entrySet()) { if (entry.getKey() != null && entry.getValue() != null) { this.cardPanel.add(entry.getValue(), entry.getKey()); } } add(this.cardPanel, BorderLayout.CENTER); } } private static String getGraticuleLabel(String graticuleType) { String labelText = null; if (UTMGraticuleLayer.GRATICULE_UTM.equals(graticuleType)) labelText = "Global UTM"; else if (MGRSGraticuleLayer.GRATICULE_UTM_GRID.equals(graticuleType)) labelText = "UTM Grid"; else if (MGRSGraticuleLayer.GRATICULE_100000M.equals(graticuleType)) labelText = "100km"; else if (MGRSGraticuleLayer.GRATICULE_10000M.equals(graticuleType)) labelText = "10km"; else if (MGRSGraticuleLayer.GRATICULE_1000M.equals(graticuleType)) labelText = "1km"; else if (MGRSGraticuleLayer.GRATICULE_100M.equals(graticuleType)) labelText = "100m"; else if (MGRSGraticuleLayer.GRATICULE_10M.equals(graticuleType)) labelText = "10m"; else if (MGRSGraticuleLayer.GRATICULE_1M.equals(graticuleType)) labelText = "1m"; return labelText; } private Icon getIcon(String path) { Icon icon = null; try { URL url = getClass().getResource(path); if (url != null) { icon = new ImageIcon(url); } } catch (Exception e) { String message = "Exception while loading icon"; Logging.logger().log(java.util.logging.Level.WARNING, message, e); } return icon; } private static class GraticuleTypeListRenderer implements ListCellRenderer { private ListCellRenderer delegate; private Icon icon; public GraticuleTypeListRenderer(ListCellRenderer delegate, Icon icon) { this.delegate = delegate; this.icon = icon; } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = this.delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (c != null && c instanceof JLabel) { JLabel label = (JLabel) c; Font font = label.getFont(); if (font != null) { label.setFont(font.deriveFont(Font.BOLD)); } if (this.icon != null) { label.setIcon(this.icon); } if (value != null && value instanceof String) { String graticuleType = (String) value; String labelText = getGraticuleLabel(graticuleType); label.setText(labelText); } } return c; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -